Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most reliable way to deliver emails from a users email address in rails?

I would like to allow users to send emails which are generated in my rails app from their email address .

I know I can just use my servers sendmail, and set the from address to their email address, but there is a high chance the emails will be marked as spam.

Is there a better way to do this? Can I use sendgrid, or Amazon SES or make the user input their own SMTP details.

Any suggestions or best practices would be much appreciated.

like image 993
David Barlow Avatar asked Mar 11 '11 00:03

David Barlow


People also ask

What is action mailer in Rails?

Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/views.


3 Answers

This will fail in the face of SPF. SPF is essentially a way for a domain to say "email purporting to be from this domain will only be sent from these servers", so if you send email from a user at that domain from your server, anyone who does an SPF-check is likely to mark your mail as spam.

Essentially: Don't use the From header if the mail's not from the sender, use the Sender header instead.

like image 119
nickgrim Avatar answered Nov 10 '22 12:11

nickgrim


I believe SendGrid support customising the From address. Heroku provide them as an add-on and they advertise "Complete control over the From: address." on their add-ons page

like image 29
lebreeze Avatar answered Nov 10 '22 12:11

lebreeze


Amazon SES is out of the question for this use case: they require an authorization procedure before sending as a certain email address.

Even if you prompted them for SMTP server details, that's going to set off huge red flags to any competent users. Most SMTP servers are properly configured to either require authentication during the SMTP transaction, or require a recent POP3 or IMAP connection, and that means gathering user credentials. Do you feel like asking your users to trust you with their email password?

Overall, this is actually an astoundingly bad idea, especially considering email authorship proving techniques like SPF / Sender ID. Mails sent this way through non-authorized servers are increasingly likely to get (rightfully) flagged as spam.

Would your use case allow the mails to be "From" your application, but have a "Reply-To" of the user?

like image 29
Charles Avatar answered Nov 10 '22 13:11

Charles