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.
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.
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.
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
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With