Monday, May 4, 2015

Ruby on Rails ActionMailer Configuration for Namecheap Private E-mail

Ever try setting up Ruby on Rails to use Namecheap's private e-mail to no avail. Me too. Finally figured out some settings that made things work.

First off, for your smtp settings:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => 'mail.privateemail.com',
  :port                 => 26,
  :user_name            => 'username@domain.com,
  :password             => 'yourpassword,
  :authentication       => :plain,
  :enable_starttls_auto => true  }

Of course, you can throw everything into environment variables.

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => ENV['SMTP_SERVER'],
  :port                 => ENV['SMTP_PORT'],
  :user_name            => ENV['SMTP_USER'],
  :password             => ENV['SMTP_PASSWORD'],
  :authentication       => :plain,
  :enable_starttls_auto => true  }

But the key thing here, or at least the thing that's unusual is PORT 26!!! It's right there in Namecheap's documentation but they say if you're going to use starttls - you must use port 26. That was the main thing that I seemed to stumble on. The other settings are very similar to say GMail settings.

Also, I did set my "from" address in my Mailer class to match my domain which may or may not have helped - I was too lazy to do a controlled experiment on that.

Anyway, hope that helps some peeps.