Monday, October 12, 2009

Rails ActionMailer Setup for Yahoo SMTP

I have been working on a new project lately. Today I decided to setup email notification system for it. I first thought of using AuthSmtp (http://www.authsmtp.com/) to send out emails to users but then I opted for yahoo email where I had also registered the domain.

I setup a new email address from which I am going to send out emails to the users of my system. Like activation emails, new message notifications, etc.

But the code kept throwing"Errno::ECONNRESET (Connection reset by peer):' error whenever I tried to connect to yahoo's smtp server and send a message. It took me a while to figure what the problem was: Yahoo told me to use port 465; whereas the correct port number to use is 587!

So to save you couple of hours filled with frustration and hair pullings, here's the action_mailer setup that works:


ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.bizmail.yahoo.com",
:port => 587,
:domain => "www.your-domain.com",
:user_name => "username@your-domain.com",
:password => "some-password" ,
:enable_starttls_auto => true,
:authentication => :plain
}