0

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.

Mike F.
  • 69
  • 1
  • 9
  • Make sure all necessary ports are open in your production environment. – bwest Apr 10 '16 at 16:56
  • The SendGrid and Mandrill port numbers are both the same (587). It worked with Mandrill without changing anything. – Mike F. Apr 10 '16 at 23:27
  • I tried to use SendInBlue instead of SendGrid. Again it worked locally in development but does not work in production on OpenShift. So I guess that is where the problem is. – Mike F. Apr 14 '16 at 01:29
  • Tried again with SparkPost ports 587 and 2525. Same result. Nothing works on OpenShift except for Mandrill. Now I'm really stuck. – Mike F. Apr 16 '16 at 23:42
  • this is a longshot but try changing the line `:authentication => "plain"` to `:authentication => :plain` – bwest Apr 16 '16 at 23:49
  • I just tried that. I was hopeful but it didn't help. Thanks anyway. I can't believe I'm the only one using this combination of services. Maybe I am. Maybe I need to pay to get some support from RedHat. :( – Mike F. Apr 17 '16 at 16:22
  • I've got a friend that is an evangelist for OpenShift. Can you email me at brandon @ sendgrid.com and I'll try to help? – bwest Apr 18 '16 at 14:52

2 Answers2

0

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

TheSteve0
  • 3,530
  • 1
  • 19
  • 25
  • I'm pretty much doing all of that. But I'm using ActionMailer in Rails 4. ActionMailer uses the Mail gem they mention. I've also found other SendGrid docs showing the configuration when using ActionMailer which is the same as what I did. I think the problem is more with OpenShift since I get the same result with several different transactional email services. – Mike F. Apr 22 '16 at 01:34
0

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
Daniel Loureiro
  • 4,595
  • 34
  • 48
  • Thanks for the detailed answer. But the telnet works from the OpenShift server where I'm running rails: > telnet smtp-relay.sendinblue.com 587 Trying 94.143.17.4... Connected to smtp-relay.sendinblue.com. Escape character is '^]'. 220 smtp-relay.sendinblue.com ESMTP Sendinblue SMTP 2.0 – Mike F. Apr 30 '16 at 01:00
  • And I do have the correct hostname in my rails configuration. – Mike F. Apr 30 '16 at 01:04
  • Can you open a rails console on this server? `RAILS_ENV=production rails c`. Then, try to send an email from there. `MyMailer.new(param_1, param_2).deliver`. What it returns? – Daniel Loureiro Apr 30 '16 at 21:50
  • Having other problems running rails console on OpenShift. Working on fixing that but maybe it's not worth it. I might have to find another host. – Mike F. May 02 '16 at 00:07