ActionMailer不在开发Rails 4中发送邮件

Don*_*n P 45 ruby-on-rails actionmailer ruby-on-rails-4

为什么这封邮件不发送任何邮件?(或任何调试的想法?)

在my_app/config/environments/development.rb中我有这样的代码:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'my_app.com',
    user_name:            ENV['GMAIL_USERNAME'],
    password:             ENV['GMAIL_PASSWORD'],
    authentication:       'plain',
    enable_starttls_auto: true  }
Run Code Online (Sandbox Code Playgroud)

然后在〜/ .bash_profile的本地计算机上我有这个代码:

export GMAIL_USERNAME='blah@my_app.com'
export GMAIL_PASSWORD='***'
Run Code Online (Sandbox Code Playgroud)

当我$ env在终端中运行时,我看到两个环境变量都已正确设置.

我也重新启动了我的rails服务器.

Dan*_*nny 110

你应该添加

config.action_mailer.perform_deliveries = true
Run Code Online (Sandbox Code Playgroud)

默认情况下,这是假的,防止从您的开发环境发送邮件...

  • 我建议打开config.action_mailer.raise_delivery_errors = true,这样就不会吞下传递问题。 (2认同)

Aar*_*uss 13

对于没有使用smtp的人,将交付方法切换到sendmail除了明确设置要执行的交付之外,还帮助我:

config.action_mailer.delivery_method = :sendmail
Run Code Online (Sandbox Code Playgroud)


Mic*_*awn 9

如果您在从控制台发送电子邮件时遇到问题,则必须在邮件上调用发送方法.

MyMailer.create_email.deliver
Run Code Online (Sandbox Code Playgroud)