Mike F.
Mike F.

Reputation: 69

Transactional Email not sent from rails server in production on OpenShift but works fine in development

I have a Ruby on Rails (v4.1.5) application running on RedHat’s OpenShift. I was in the process of switching from Mandrill to SendGrid. In development I was able to add the following to my development.rb config file:

ActionMailer::Base.smtp_settings = {
  :address   => "smtp.sendgrid.net",
  :port      => 587,
  :authentication => "plain",
  :domain => ENV["DOMAIN_NAME"],
  :enable_starttls_auto => true,
  :user_name => ENV["SENDGRID_USERNAME"],
  :password  => ENV["SENDGRID_PASSWORD"]   
}

And I could continue to use ActionMailer the same way I did before. I tested it locally and received emails and the headers showed they came through sendgrid.

Then I added this same code to production.rb and deployed to OpenShift. I added the new SENDGRID username and password environment variables used in the code above and verified they were set correctly on OpenShift.

But when I tested it, the log file says it sent the email to the correct email address but it doesn’t show up on my SendGrid dashboard and I have not received the email.

Does anyone know of any other log files on OpenShift that might show more info? I only looked at app-root/runtime/repo/log/production.log.

I have tried removing the enable_starttls_auto field above but nothing changed.

How can I debug this problem? I don’t know if it’s on the OpenShift side or SendGrid.

Upvotes: 0

Views: 1271

Answers (2)

Daniel Loureiro
Daniel Loureiro

Reputation: 5383

First, do a direct connection with Telnet:

telnet smtp-relay.sendinblue.com 587
Trying 94.143.17.4...

If you get this error:

telnet: Unable to connect to remote host: Connection timed out

then, the problem isn't in Rails.

In my case, the problem was in the port number. My server is running on DigitalOcean which blocks connections to 587 ports, unless you ask them to unblock it, and they will unblock based on the hostname too, which means that it can work with mandrill but not with others.

Remember "2525" is the new "587", and this is true even for SendinBlue.


Other things to check if you get a timeout on telnet:

  1. hostname: it's usual to people use "smtp.sendinblue.com" instead of "stmp-relay.sendinblue.com".
  2. port: Give 2525 a try.
  3. ipv6 vs ipv4: check if the hostname is being translated as a IPv4. If not, try to disable IPv6, by editing "/etc/sysctl.conf".
  4. firewall / AppArmor: check if they aren't the culprits here.
  5. hostname resolution: run the same telnet command on a machine that you know the email sending is working. Check if the translated ip (the xxx part of "Trying xxx...") is the same. If not, go back to your server and replace the hostname with this ip. If works, change your /etc/hosts and force the hostname to use this ip.

Disabling IPv6:

add the following lines to your /etc/sysctl.conf:

#disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Changes requires reboot.

You can test if IPv6 is disabled or not with

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

Upvotes: 0

TheSteve0
TheSteve0

Reputation: 3526

This article should help. I am not a Ruby expert so I can't really help.

https://developers.openshift.com/external-services/sendgrid.html

I know we have a lot of users using openshift and sendgrid.

Here is a PHP code repo - I know I know not the right language but a good example

https://github.com/sendgrid/openshift-sendgrid-php

Upvotes: 0

Related Questions