2013-08-27 24 views
2

發送電子郵件對我們的業務至關重要。我們目前計劃使用Mandrill作爲我們的主要電子郵件提供商,但是如果他們的服務停止運行,那麼我們有一個備份服務(SendGrid)發生任何失敗是非常重要的。SMTP動作郵件故障轉移在Ruby On Rails

由於SMTP配置是在Application.rb中加載的(我相信這只是在應用程序加載時纔會發生),如果發送電子郵件失敗,我怎麼才能智能地回退到另一個SMTP服務?

+0

嗨,你能配置備份SMTP服務器?如果是的話,你可以更新與你如何解決這個用例的問題嗎? – vijay

回答

-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 
3

,而不是做在軌道上的切換/回退,推薦SendGrid gives customers to whom email sending is crucial是設置(例如使用Postfix)本地郵件服務器和設置郵件服務器使用SendGrid作爲一個聰明的主人。

在你的情況,你可以設置Mandrill作爲中繼服務器,SendGrid作爲備份中繼服務器。如果Mandrill發生故障,您的本地服務器將負責通過Mandrill和SendGrid進行發送。