Where i can read complete manual to configure SMTP for Rails?

丶灬走出姿态 提交于 2019-12-24 08:34:33

问题


I newbie in Rails, and i have some question. I setup simple application with Devise plugin, deploy it on production server (Ubuntu on Linode, nginx + passenger) via Capistrano. And now try to send emails (password recovery, email confirmation and etc from Devise).

But it doesent work.

I have this lines in /enviroments/production.rb

  config.action_mailer.default_url_options = { :host => "myhostname.com" }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true

And when i try to send email from my app, i get 500 error "We're sorry, but something went wrong. " (by Passenger). In log/production.log

Net::SMTPServerBusy (451 4.3.0 Temporary system failure. Please try again later.)

I use exim4 as mail server. Also i try install sendmail and change

config.action_mailer.delivery_method = :sendmail

Emails start sends but application work so slow.

So, my question is: what i need to do with my problem and where i can read complete manual or documentation to configure exim4 for work with rails application?

Thanks.


回答1:


According to chapters 5 and 5.1 of ActionMailer official doc : http://guides.rubyonrails.org/action_mailer_basics.html

We can see that there are no ':exim4' option available as 'delivery_method'.

So I would suggest to "cheat" ActionMailer that he is using sendmail (though he will use exim4). Use the following configuration in your config/enviroments/production.rb file :

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

Arguments match the following exim4 options :

  • -t option causes the recipients of the message to be obtained from the To:, Cc:, and Bcc: header lines in the message instead of from the command arguments.
  • -i option prevents a line containing just a dot from terminating the message. Only an end-of-file does so.

Don't use the -t option.

In order to configure properly your Exim4 deamon, I suggest this quick how-to : http://noosfero.org/Development/MailSending

I highly recommend you choose "smarthost" on the first screen instead of "Internet site".

This is because mail providers of the Internet (gmail, yahoo, etc...) do block any e-mails that come from an unkown IP adresses on Internet by default (this include your new server IP adress of course).

If you choose 'smarthost' your server will have to connect to an existing (and trusted) mail server (gmail, yahoo, etc...) in order to forward its own e-mail messages. This will ensure your e-mails get their ways up to their destination.

=== UPDATE

I had problem making it working with -t optin since some version of rails (3.2). I had the following error in my /var/www/my_app/log/production.log :

Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25)

So I removed the -t option as rails was not including anymore the To: field in the message and rather sent it in the command line.

I found some other developper having a similar issue on this app : gitlabhq

I hope this help people to make rails working with exim4.




回答2:


Debian 8 + Rails4.2.6 + Exim version 4.84_2

I added to my config/enviroments/production.rb file:

config.action_mailer.default_options     = { from: 'mybox@hostname.com' }
config.action_mailer.default_url_options = { host: 'hostname.com' }
config.action_mailer.perform_deliveries    = true
config.action_mailer.raise_delivery_errors = true

and clear(commented) from delivery_method and sendmail_settings params:

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

And it's work!

For me Douglas answer didn't work.



来源:https://stackoverflow.com/questions/9748239/where-i-can-read-complete-manual-to-configure-smtp-for-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!