Why Rails/ActionMailer needs sendmail to send emails? Why not directly from Ruby?

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)?

ActionMailer will connect to any SMTP server you like. The configuration options from the guide outline how to do that.

By default, email send via ActionMailer does use a background job, if you have a background job library installed.

So, it should do exactly what you want already.

I was wondering why delegate the delivery to sendmail instead of using Ruby SMTP directly.

ActionMailer will connect to any SMTP server you like

This is for your mail server, not to deliver to the end user email over SMTP.

The question was more about having the mail server built-in in the rails application. I found this for example: GitHub - postalserver/postal: ✉️ A fully featured open source mail delivery platform for incoming & outgoing e-mail

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 :slight_smile:

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.

Ah, of cause! I never use cloud providers but my own mail servers running either Postfix (SMTP) and Dovecot (IMAP) or using Zimbra.

I prefer Postfix/Dovecot some of my customers prefer Zimbra.

Postfix/Dovecot is some work to fulfil all the conditions for modern mail servers.

your could start with mailcow to setup an own mail server in a docker image.

The issue is not Rails but running a widely accepted mail server (accepted by other mail servers).