4

发送电子邮件对我们的业务至关重要。我们目前计划使用 Mandrill 作为我们的主要电子邮件提供商,但如果他们的服务出现故障,我们有一个备份服务 (SendGrid) 来应对任何故障,这一点非常重要。

由于 SMTP 配置是在 Application.rb 中加载的(我相信在应用程序加载时只有一次),如果发送电子邮件失败,我如何智能地回退到另一个 SMTP 服务?

4

2 回答 2

4

与在 Rails 中进行切换/回退不同,SendGrid 向对电子邮件发送至关重要的客户提供的建议是设置本地邮件服务器(例如使用Postfix)并将邮件服务器设置为使用 SendGrid 作为智能主机。

在您的情况下,您可以将 Mandrill 设置为中继服务器,将 SendGrid 设置为备用中继服务器。如果 Mandrill 出现故障,您的本地服务器将负责通过 Mandrill 和 SendGrid 进行发送。

于 2013-08-27T16:36:20.963 回答
-1

这是我的解决方案:

class UserMailer < ActionMailer::Base

  def welcome_message(user, custom_email=nil, settings)
    ActionMailer::Base.username = settings["username"]
    ActionMailer::Base.password = settings["password"]
    ActionMailer::Base.server = settings["server"]
    ActionMailer::Base.port = settings["port"]

    target_email = custom_email || user.email
    mail(to: target_email, subject: 'Welcome')
  end
end
于 2013-08-27T16:31:23.743 回答