Rails droplet, rails 4, gmail not sending

May 22, 2015 8.6k views
Email Ruby on Rails

I have the following setup:
Ubuntu Ruby on Rails on 14.04 (Nginx + Unicorn) (London location)

I have manually upgraded it to Rails 4.
The application is running fine, but I cannot send e-mails.

I have followed the tutorials on adding the Gmail MX records, the domain is pointed to the droplet, so everything is fine.

The account to send from is on Gmail.

Rails settings are the following:

config.actionmailer.smtpsettings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: :login,
enablestarttlsauto: true,
username: Rails.application.secrets.emailproviderusername,
password: Rails.application.secrets.email
mailer.defaulturloptions = { :host => "smtp.gmail.com" }
config.actionmailer.deliverymethod = :smtp
config.actionmailer.performdeliveries = true
config.actionmailer.raisedelivery_errors = false

By testing it on a local machine, the code itself can send e-mails using the same credentials both in development and in production mode, so not likely that it is the code.

I have also configured postfix on the server (although I am not sure if that was necessary), and could send a test e-mail from the command line.

Mails are still not working from Rails.

Any ideas where to look for the problem ???


3 Answers

I actually figured this out.

I set this in production, to actually see the error:
config.actionmailer.raisedelivery_errors = true

and it turned out that sending the email timed out, which after some research led me here:

default url is you domain

config.actionmailer.defaulturloptions = { :host => "domain.com" }

Just for reference for people with trouble getting email sending working that might reach this page in the future:

For some time now Digital Ocean droplets have SMTP traffic blocked by default (because of anti-spam regulations). If you need SMTP enabled on your droplet you have to issue a support ticket asking for it to be enabled.

Have another answer? Share your knowledge.