ruby-on-rails

Send email without external SMTP service


Okay, confused here. I can send emails just fine from my rails app using this service, http://www.mailgun.com/ and their gem.

Responses I've received to Can webmail work without an SMTP server? lead me to believe you can send an email with PHP/Ruby, with no external service.

  1. Can I send email directly from my application? Maybe in a worker?
  2. If that's the case, why do people use services such as mail chimp and mail gun?
  3. How do I do this in my rails app? Is it a simple matter of tweaking my ActionMailer configuration?

Solution

  • You can host your own mail server on localhost or another machine in your network. There are Open Source mail servers. These are normally called Mail Transfer Agents (MTA). Some examples are Sendmail and Postfix. There are also others depending on your needs and operating system.

    To directly answer your questions:

    1. Yes, and a worker would be a good place for this if performance was an issue.
    2. For convenience, expertise, reliable delivery and reputation. Running your own secure mail server can be non-trivial. It becomes another server to configure, monitor and keep secure. With all the spam on the internet now, keeping your server off the blacklists is very important and depending on the volume and importance of the email you send, it might simply make more sense to leave this with the experts. Mailgun, sendgrid, Amazon SES etc.
    3. Yes, it is simply a matter of configuration. You can configure ActionMailer to use localhost, your own hosted email server, or any of the 3rd-party Email Service Providers.