Rails droplet, rails 4, gmail not sending

May 22, 2015 4k 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: "",
port: 587,
domain: "",
authentication: :login,
enablestarttlsauto: true,
username: Rails.application.secrets.emailproviderusername,
mailer.defaulturloptions = { :host => "" }
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 ???


2 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 => "" }

Have another answer? Share your knowledge.