开发者

problem with Actionmailer "Timeout::Error"?

im trying to send a email with action mailer and it gives me a Timeout::Error (execution expired): even though in the console it says that the e mail is sent: it shows

    Sent mail to aldeirm2@gmail.com

then displayes the e mail that was sent then it shows the following error:

Timeout::Error (execution expired):
  /usr/lib/ruby/1.8/timeout.rb:60:in `open'
  /usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
  /usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
  /usr/lib/ruby/1.8/net/smtp.rb:525:in `start'
  app/models/appointment.rb:10:in `tomorrows_appointments'
  app/models/appointment.rb:8:in `each'
  app/models/appointment.rb:8:in `tomorrows_appointments'
  app/controllers/show_appointments_controller.rb:11:in `send_email'
  -e:2:in `load'
  -e:2

Rendered rescues/_trace (35.8ms)
Rendered rescues/_request_and_response (0.3ms)
Rendering rescues/layout (internal_server_error)

here is my settings:

config.cache_classes = false
config.whiny_nils = true
config.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs        开发者_如何转开发                 = true
config.action_controller.perform_caching             = false

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :enable_starttls_auto => true,
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domian               => "gmail.com",
  :authentication       => :login,
  :user_name            => "username",
  :password             => "blablabla",
}

i also tried setting authentication to :plain and using username@gmail.com as the user_name with no hope.

any ideas


I saw a typo there: you wrote :domian => "gmail.com",

instead of

:domain => "gmail.com",


SMTP requests seem to time out occasionally, probably depending on how long you've set for timeouts. The other problem you'll get is a delay in the web-app while the user waits for your server to communicate with Gmail's SMTP server.

I know gmail is a popular option for new rails apps, but I don't think it's a long-term solution since you have to send the mail through a particular gmail account which has daily sending limits. And even with other accounts, I have found that SMTP timeouts are a problem.

Now I am using SendGrid to send emails and have found that using sendgrid as a relayhost via postfix is the favourable option. This means the user gets a response from the web-app faster and the mail is queued through postfix and then sent via sendgrid (so no more timeouts!).

See here for sendgrid's postfix setup instructions: http://wiki.sendgrid.com/doku.php?id=postfix

Then, in your rails environment, you just need something like the following:

config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
  :location       => '/usr/sbin/sendmail',
  :arguments      => '-i -t'
}


In case anyone else has the same problem:

make sure that your firewall allows outgoing connections to port 587

For iptables, you can list all existing rules with:

sudo iptables -L

have a look here for the necessary rules.

If you're using an AWS instance, have a look at your security groups.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜