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

时间:2023-01-16 10:19:20

Why is this mailer not sending any mail? (Or any ideas for debugging?)

这个邮差为什么不寄邮件?(对调试有什么想法吗?)

In my_app/config/environments/development.rb I have this code:

在my_app / config /环境/发展。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  }

Then on my local computer in ~/.bash_profile I have this code:

然后在我的本地电脑上~/。bash_profile我有这个代码:

export GMAIL_USERNAME='blah@my_app.com'
export GMAIL_PASSWORD='***'

When I run $ env in my terminal, I see that both environment variables are correctly set.

当我在终端上运行$ env时,我看到两个环境变量都被正确设置了。

I have also restarted my rails server.

我还重新启动了rails服务器。

4 个解决方案

#1


95  

You should add

你应该添加

config.action_mailer.perform_deliveries = true

as by default this is on false, preventing mails to be sent from your development environment...

默认情况下,这是在false上,防止从开发环境发送邮件……

#2


10  

For anyone not using smtp, switching the delivery method to sendmail helped me in addition to explicitly setting deliveries to be performed:

对于任何没有使用smtp的人来说,将传递方法切换到sendmail可以帮助我明确地设置要执行的交付:

config.action_mailer.delivery_method = :sendmail

#3


6  

If you're having issues sending email from console, you have to call the deliver method on your mail.

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

MyMailer.create_email.deliver

#4


0  

So I've figured it out. Having the line ActionMailer::Base.delivery_method = :smtp in config/environment.rb overrides ActionMailer::Base.delivery_method = :test in config/environments/test.rb.

我算出来了。在配置/环境中具有行ActionMailer: Base.delivery_method =:smtp。rb重写ActionMailer: Base.delivery_method =:在配置/环境/test.rb中的测试。

So, delete that line, ActionMailer::Base.delivery_method = :smtp from config/environment.rb and place it in config/environments/production.rb. That allows you to place ActionMailer::Base.delivery_method = :test in config/environments/test.rb and the version you want in config/environments/development.rb. I made development.rb :test as I populated my database using Faker and changed it to :smtp so I was sure that real emails were sent as an additional check.

因此,从配置/环境中删除ActionMailer: Base.delivery_method =:smtp。把它放在配置/环境/产品中。这允许您在配置/环境/测试中放置ActionMailer: Base.delivery_method =:test。rb和您想要的配置/环境/开发中的版本。我做开发。rb:测试时,我使用Faker填充我的数据库,并将它更改为:smtp,因此我确信真实的电子邮件是作为额外的检查发送的。

Note: You must restart your server for these changes to take effect.

注意:您必须重新启动服务器以使这些更改生效。

Another note: Heroku's current SendGrid Instructions (https://devcenter.heroku.com/articles/sendgrid) put the SendGrid Heroku configuration code in a new config/initializers/mail.rb file which will likely require removing its last line and placing the desired version in each config/environments/[production.rb, development.rb, test.rb]

另一个注意事项:Heroku当前的SendGrid指令(https://devcenter.heroku.com/articles/sendgrid)将SendGrid Heroku配置代码放入一个新的配置/初始化器/邮件中。rb文件,可能需要删除最后一行,并在每个配置/环境/[产品]中放置所需的版本。rb、发展。rb,test.rb]

#1


95  

You should add

你应该添加

config.action_mailer.perform_deliveries = true

as by default this is on false, preventing mails to be sent from your development environment...

默认情况下,这是在false上,防止从开发环境发送邮件……

#2


10  

For anyone not using smtp, switching the delivery method to sendmail helped me in addition to explicitly setting deliveries to be performed:

对于任何没有使用smtp的人来说,将传递方法切换到sendmail可以帮助我明确地设置要执行的交付:

config.action_mailer.delivery_method = :sendmail

#3


6  

If you're having issues sending email from console, you have to call the deliver method on your mail.

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

MyMailer.create_email.deliver

#4


0  

So I've figured it out. Having the line ActionMailer::Base.delivery_method = :smtp in config/environment.rb overrides ActionMailer::Base.delivery_method = :test in config/environments/test.rb.

我算出来了。在配置/环境中具有行ActionMailer: Base.delivery_method =:smtp。rb重写ActionMailer: Base.delivery_method =:在配置/环境/test.rb中的测试。

So, delete that line, ActionMailer::Base.delivery_method = :smtp from config/environment.rb and place it in config/environments/production.rb. That allows you to place ActionMailer::Base.delivery_method = :test in config/environments/test.rb and the version you want in config/environments/development.rb. I made development.rb :test as I populated my database using Faker and changed it to :smtp so I was sure that real emails were sent as an additional check.

因此,从配置/环境中删除ActionMailer: Base.delivery_method =:smtp。把它放在配置/环境/产品中。这允许您在配置/环境/测试中放置ActionMailer: Base.delivery_method =:test。rb和您想要的配置/环境/开发中的版本。我做开发。rb:测试时,我使用Faker填充我的数据库,并将它更改为:smtp,因此我确信真实的电子邮件是作为额外的检查发送的。

Note: You must restart your server for these changes to take effect.

注意:您必须重新启动服务器以使这些更改生效。

Another note: Heroku's current SendGrid Instructions (https://devcenter.heroku.com/articles/sendgrid) put the SendGrid Heroku configuration code in a new config/initializers/mail.rb file which will likely require removing its last line and placing the desired version in each config/environments/[production.rb, development.rb, test.rb]

另一个注意事项:Heroku当前的SendGrid指令(https://devcenter.heroku.com/articles/sendgrid)将SendGrid Heroku配置代码放入一个新的配置/初始化器/邮件中。rb文件,可能需要删除最后一行,并在每个配置/环境/[产品]中放置所需的版本。rb、发展。rb,test.rb]