For most Rails projects you are going to use Sendgrid, Postmark, AWS SES, etc. I also have knowledge about IP reputation, warming, SPF, DKIM, DMARC, etc.
However you are always hostage of some cloud provider to deliver your emails.
What if you want to use only on your own infrastructure/servers to send the emails (e.g. because you have large volumes)?
I see that the only option for sending from your own server in ActionMailer is using sendmail: basically Ruby will invoke an external command for each email.
Why is that necessary? Why not send directly from Ruby code (e.g. connecting to the SMTP server of the recipient in a background job)?
Hi Marco, integrating a Mailserver into the default rails package, i would see as a overkill. If something like Postal would be available as a gem, that you could optionally plug-in could be a nice idea for apps that should be able for a fully-mail support including receiving emails. But such a gem would need heavy maintenance. May the day come if the demand is big enough
You say, you know about SPF, DKIM, DMARC etc. probably reverse DNS lookup?
Then you know how hard it is to convince a modern mail server, to accept incoming mail.
You normally have some mail service (you need a valid sender address) so my advice: use a authenticated account at this service to send your mails.
Otherwise most mail server, especially big ones like Google, GMX will reject your mails.
@mameier I know that the easiest solution is to use a service like Sendgrid, Postmark, AWS SES, etc. and I do that all the time.
However my question here is more about if it’s possible to be independent from these cloud providers. I would be happy to hear from people that made it and are sending from their own servers.
I find myself in a situation where I need to send emails exclusively from my own infrastructure and servers. This is primarily because of the high email volume my application generates, and I want full control over the email delivery process. I’ve noticed that the default option in Rails’ ActionMailer often involves invoking an external command like sendmail . However, I’m curious about the possibility of sending emails directly from my Ruby code by connecting to the SMTP server of the recipient.
One possible reason why this particular option hasn’t been made easier is that it would consume one of your processes until the message handshake was complete. E-mail is a store-and-forward proposition, going all the way back to the original intent of the ARPANET. There is no expectation that the recipient is available or there is even a route to their machine. Any sender has to be prepared to cache outgoing messages until the send succeeds (or some timer or attempts counter is exceeded). Sendmail (and anything that quacks like it) provides all that nuance and patience.
There are many other possible reasons, but that’s the one that leapt to mind…
Sendmail is a MTA. At the most basic level a MTA connects to the recipient SMTP to deliver the message. But there is more to it than that. Since it may be offline it has a retry mechanism, queues to control the rate of mail flow, etc.
Could you implement a MTA in Ruby? Sure, but that’s really outside the scope of Rails. Rails’ job is to hand it off to a MTA to send it out. Since there are so many good MTAs out there (qmail is my preferred) it seems better to just set that up rather than write a whole MTA in Ruby.