Search code examples
ruby-on-railsemailgmail

rails mailer failing to send to gmail; works with sendgrid


I have a rails 4 application in production (for years) when suddenly last week it stopped successfully sending mail to gmail.

The error message is:

E, [2016-04-09T17:16:49.293552 #14465] ERROR -- : 2016-04-09T17:16:49+0000: [Worker(delayed_job host:ip-10-18-148-31 pid:14465)] Job Class#email_sample_complete (id=292861) FAILED (5 prior attempts) with EOFError: end of file reached

The config (which has worked for a year / password and domain obscured for security) is:

ActionMailer::Base.smtp_settings = {
  :enable_starttls_auto => true,
  :address        => "smtp.gmail.com",
  :port           => 587,
  :domain         => "[email protected]",
  :authentication => :plain,
  :user_name      => "[email protected]",
  :password       => "mypassword"
}

I tested the credentials manually and was able to log in using them, so that hasn't changed.

On a hunch, I changed the email server and creds to point to sendgrid, and those emails went through. So everything works except for the connection to gmail.

We had not made any code changes or deployments. To be safe I redeployed a known version of the code that was previously known to be safe and restarted the web server and delayed_job to make everything was picked up. No joy.

I googled the error message and the general consensus was that this was caused by the email server being down ... so I tried the old config again a few times over the following days. Still not working.

Scratching my head here. A known working config suddenly stopped working with no code change or env change. Has something changed on google's side?


Solution

  • The solution was in the configuration.

    I changed the domain from....

    :domain         => "[email protected]",
    

    to ....

    :domain         => "gmail.com",
    

    And the EOF error disappeared. Google must have made a change on their side that required the domain to be gmail.com. I can't think of another reason why the configuration suddenly stopped working after over a year with nary a problem.