21

I'm trying to send emails in a Rails app. It works if I use Gmail, but it's not working if I use Mandrill. I'm getting this timeout error with Mandrill. Not sure what I'm doing wrong. With both Gmail and Mandrill I am setting the username and password/api_key using environment variables. The only difference between the two setups is what you see below. Any ideas?

Timeout::Error in RegistrationsController#create

execution expired
Rails.root: /Users/michaeljohnmitchell/Sites/pre

Application Trace | Framework Trace | Full Trace
app/models/user.rb:38:in `send_welcome_email'

Mandrill Doesn't work

config.action_mailer.smtp_settings = {
  :address   => "smtp.mandrillapp.com",
  :port      => 25,
  :user_name => ENV["MANDRILL_USERNAME"],
  :password  => ENV["MANDRILL_API_KEY"]
}

Gmail Works

config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
 authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
}

2 Answers 2

37

use port 587 for mandrill, happend the same to me :)

this is because port 25 is sending plain text and port 587 sends SSL encoded emails (which I think is the whole mandrill idea).

I have no idea why they set it to port 25 in their examples.

1
  • 1
    I had a similar issue where some emails were going out and others were failing due to Net::OpenTimeout. Switching to port 587 fixes this. Maybe everyone and their mother are using 25 so it's just too much traffic on that port? Jul 25, 2014 at 17:30
0

Here are a few things you can try based on the information you provided:

  1. make sure the correct information is in each of your environment files (production.rb and development.rb)

  2. try hardcoding the username and password for mandrill as opposed to using environmental variables (for testing only)

3
  • 1
    hard coding can be used to test if you're having issues with environmental variables.
    – django-d
    Oct 27, 2012 at 23:43
  • 1
    It can be a great idea during testing your development environment. What Naoise Golden probably means is that you should ALWAYS be very careful not to commit any changes to git during testing so as not to expose your username or passwords.
    – SoEzPz
    Oct 12, 2014 at 16:36
  • tip: use ENV.fetch("REQUIRED_ENV_VAR") to ensure that env var is set Oct 29, 2015 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.