且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Rails:ActionMailer 的运行时配置?

更新时间:2023-10-02 23:44:22

(Rails 3)

因为我这样称呼邮件程序:

Since I call mailer like this:

CustomerMailer.customer_auto_inform(@form).deliver

在 CustomerMailer 类中,我有私有方法:

In CustomerMailer class I have private method:

def init_email_account(shop_mail)
  ActionMailer::Base.raise_delivery_errors = true
  ActionMailer::Base.smtp_settings = {
    :address              => shop_mail.address,
    :port                 => shop_mail.port,
    :domain               => shop_mail.domain,
    :user_name            => shop_mail.user_name,
    :password             => shop_mail.password,
    :authentication       => shop_mail.authentication.name,
    :enable_starttls_auto => shop_mail.enable_starttls_auto
  }
end

在调用发送电子邮件的 ma​​il() 之前,您需要调用私有方法 init_email_account 以从数据库填充 smtp_settings.shop_mail 是存储有关邮件帐户设置的数据的模型.

Before calling mail() which sends email you need to call private method init_email_account to populate smtp_settings from database. shop_mail is model which stores the data about mail account settings.

HTH