0

我有一个发送电子邮件的应用程序,我在 application.rb 文件中配置了 mandrill。

config.action_mailer.smtp_settings = {
  address:              'smtp.mandrillapp.com',
  port:                 587,
  domain:               'translatr.herokuapp.com',
  user_name:            ENV["MANDRILL_USERNAME"], 
  password:             ENV["MANDRILL_PASSWORD"], 
  authentication:       'plain',
  enable_starttls_auto: true  }

但是,我不想在开发和测试期间发送邮件,但我在生产中发送邮件。我是通过将此设置移动到 production.rb 来做到这一点吗?还是有其他方法可以做到这一点?

4

3 回答 3

1

将您的设置移动到 production.rb,然后电子邮件将仅在生产中发送

于 2013-11-08T09:44:10.000 回答
1

您只想使用此设置production.rb。因为其他环境还有其他有用的设置:

test.rb你会发现类似的东西:

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

这允许您编写规范,通过检查是否ActionMailer::Base.deliveries.size增加来检查邮件是否会在生产中发送。

并且开发环境通常不应该发送电子邮件。它只是登录到development.rb将在生产中发送的电子邮件。对于调试也非常有用。

于 2013-11-08T10:51:43.553 回答
0

您可以检查当前的 rails 环境,而不是更改 application.rb 中的设置。如果 env 是生产调用 mail 方法。

      send_mail if Rails.env.production?

如何判断 Rails 是否在生产中?

于 2013-11-08T09:45:24.910 回答