use*_*956 2 email ruby-on-rails actionmailer
我在config/environments/development.rb中有以下内容
# ActionMailer settings
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'gmail account',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true}
Run Code Online (Sandbox Code Playgroud)
我有以下Mailer和方法来测试发送电子邮件
class EventMailer < ActionMailer::Base
default from: "exmaple@gmail.com"
def test_email
mail(to: "Me <myemail@mail.com", subject: 'Test email')
end
end
Run Code Online (Sandbox Code Playgroud)
在我的一个控制器方法中,我有
EventMailer.test_email().deliver
Run Code Online (Sandbox Code Playgroud)
我可以在终端上看到消息显示它已被发送(我相信这是日志?),但我没有收到任何实际的电子邮件.我是ActionMailer的新手,只是按照红宝石指南网站上的步骤操作,但它不起作用.不知道我要离开的是什么.我尝试时没有错误显示在我的终端中,我知道我的smtp_settings是正确的,因为我可以使用rubys Net :: SMTP在我的ruby解释器中使用与上面相同的smtp设置发送电子邮件.我只是无法使用ActionMailer.任何帮助表示赞赏!