[英]Rails 4 Mailer not sending email
我正在尝试使用Rails 4发送电子邮件。服务器未引发任何错误,但我无法在我的邮箱中收到邮件...这是我的配置:
环境/development.rb
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'no-reply@website.com'}
我正在这样发送电子邮件:
user_mailer.rb
def deliver_password_reset_instructions(user)
mail :to => user.email, :subject => 'Instructions pour la reinitialisation de votre mot de passe'
end
user.rb
def deliver_password_reset_instructions!
reset_perishable_token!
UserMailer.deliver_password_reset_instructions(self)
end
是否有人知道为什么它不发送电子邮件?
您的问题是您正在生成电子邮件,但实际上并未发送 。
UserMailer.deliver_password_reset_instructions(self).deliver
实际上会传送您正在创建的电子邮件。
阅读http://guides.rubyonrails.org/action_mailer_basics.html#walkthrough-to-generating-a-mailer (第2.1.4节-调用邮件程序),了解有关如何在应用程序中使用邮件程序的更多详细信息。
编辑: deliver
已被弃用,在Rails的4.2,有利于任deliver_now
或deliver_later
。 为了实现与从先前版本的Rails中进行deliver
相同的行为,您应该使用deliver_now
- deliver_later
旨在与ActiveJob和后台作业处理器一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.