Add*_*dsy 54 ruby-on-rails actionmailer ruby-on-rails-3
我敢肯定这已被问过一百万次,但我找不到任何对我有用的东西,所以我再问一次!
我只需要一种在rails 3中使用ActionMailer发送电子邮件的方法.我已经遵循了许多教程,包括新ActionMailer上的Railscasts教程,我可以看到生成的邮件但我没有收到它们.
我尝试了许多不同的方法,但它们通常相当于配置以下设置
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:user_name => "xxx@gmail.com",
:password => "yyy",
:authentication => "plain",
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
我在config/environment.rb,config/environments/development.rb中尝试了上面的代码(当然有有效的gmail详细信息),目前在自己的初始化配置/ initialisers/setup_mail.rb中有它
我也试过几个不同的smtp服务器,包括Gmail和Sendgrid,相应地调整smtp设置,但仍然没有.我可以在终端和开发日志中看到邮件,就是这样.
有没有人知道我可能错过的任何其他问题需要设置为ActionMailer工作?如果没有这种方法可以获得有关邮件未被发送的原因的更多信息?我有
config.action_mailer.raise_delivery_errors = true
Run Code Online (Sandbox Code Playgroud)
在我的config/development.rb中设置,但开发日志仍然显示与我在终端中看到的相同.
对于它的价值,我正在使用Ubuntu 10.04笔记本电脑进行开发,以防万一需要任何特定的设置.
非常感谢
Add*_*dsy 55
好吧,我已经解决了这个问题,但是为什么这个有效,而其他方法没有,我不知道.
解决方案是在config/initialisers/setup_mail.rb中创建包含以下内容的初始化程序
if Rails.env != 'test'
email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/email.yml"))
ActionMailer::Base.smtp_settings = email_settings[Rails.env] unless email_settings[Rails.env].nil?
end
Run Code Online (Sandbox Code Playgroud)
然后我添加了config/email.yml,其中包含开发和生产电子邮件帐户的详细信息
development:
:address: smtp.gmail.com
:port: 587
:authentication: plain
:user_name: xxx
:password: yyy
:enable_starttls_auto: true
production:
:address: smtp.gmail.com
:port: 587
:authentication: plain
:user_name: xxx
:password: yyy
:enable_starttls_auto: true
Run Code Online (Sandbox Code Playgroud)
就像我说的,不知道为什么,但这似乎可以解决问题.谢谢大家指点
nat*_*vda 27
我有以下内容 config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
Run Code Online (Sandbox Code Playgroud)
实际的邮件配置,config.actionmailer.*我已经放入config\application.rb.
希望这可以帮助 :)
尝试使用'sendmail'而不是'smtp'.
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.sendmail_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:user_name => "xxx@gmail.com",
:password => "yyy",
:authentication => "plain",
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)