Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EOFError error trying to use Amazon SES via SMTP with Rails 3.1.3

I have a Rails app configured to use Amazon SES via SMTP. When I try and send email, though, it appears to timeout after a minute, and I get an EOFError. It smells like a configuration issue--the email seems to be constructed fine, and I can send myself test emails from the AWS SES console. This is in sandbox mode, and the app is running in development mode, but both the sending and receiving emails have been verified with SES, and development.rb is set up with this:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp

I've tried a million config variations; this is starting to drive me bananas. Any help or guidance would be very, very appreciated. More details:

The smtp config, which I have in an initializer:

ActionMailer::Base.smtp_settings = {
  :address        => "email-smtp.us-east-1.amazonaws.com",
  :port           => "465",
  :authentication => :plain,
  :enable_starttls_auto => true,
  :user_name      => "1234",
  :password       => "abcde"
 }

The logs with the error, a bit truncated for brevity:

Sent mail to [email protected] (59929ms)
Date: Tue, 20 Dec 2011 03:08:37 -0800
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Your invitation to Phu
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
....

Completed 500 Internal Server Error in 60564ms

EOFError (end of file reached):
  app/controllers/admin_controller.rb:61:in `block in send_invite'
  app/controllers/admin_controller.rb:46:in `send_invite'
like image 262
John McGrath Avatar asked Dec 20 '11 11:12

John McGrath


People also ask

How do I find my AWS SMTP server details?

Sign in to the AWS Management Console and open the Amazon SES console at https://console.aws.amazon.com/ses/ . Choose SMTP settings in the left navigation pane - this will open the Simple Mail Transfer Protocol (SMTP) settings page.


1 Answers

There is also a solution without the monkey-patch solution from Mihir (which, according to AWS SES documentation, http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/SMTP.Connecting.html, is the TLS wrapper solution), by using port 587 and :enable_starttls_auto option (the STARTTLS solution). So the modified config is such:

config.action_mailer.default_url_options = { host: “<example.com>” }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
    :address: “email-smtp.us-east-1.amazonaws.com”,
    :port: 587,
    :domain: “<example.com>”,
    :authentication: :login,
    :user_name: “<your aws smtp username>”,
    :password: “<your aws smtp password>”,
    :enable_starttls_auto => true
}
like image 65
philip Avatar answered Oct 12 '22 22:10

philip