【问题标题】:Change http_basic_authenticate_with credentials on fly, rails即时更改 http_basic_authenticate_with 凭据,rails
【发布时间】:2018-03-03 18:56:35
【问题描述】:

我需要用户可以即时更改 ActionMailer 设置,而无需重新启动服务器。我正在尝试在我的邮件类中这样做

class CustomerMailer < ApplicationMailer
  self.smtp_settings = {
    address:             "smtp.gmail.com",
    port:                587,
    user_name:           settings[:delivery_email_login],
    password:            settings[:delivery_email_password],
    authentication:      "plain",
    enable_sarttls_auto: true
  }

  def customers_info_email(*some_args)
    # code
end

结束

但更改要在服务器重启后才能生效。

更新

感谢 Anthony L 动态更改 smtp 设置已经解决,但我还有另一个问题。

http_basic_authenticate_with name: login, password: password

在这种情况下如何动态更改身份验证凭据?

【问题讨论】:

    标签: ruby-on-rails ruby http authentication actionmailer


    【解决方案1】:

    不要直接更改 smtp_settings,而是在邮件方法上使用 delivery_method_options。例如:

    delivery_options = {
            address:    "smtp.gmail.com",
            port:       587,
            domain:     "your_domain.com",
            user_name:  delivery_email_login,
            password:   delivery_email_password,
            authentication: :login,
            enable_starttls_auto: true
          }
    
    mail(from: from_email, 
         to: to_email, 
         subject: subject,
         delivery_method_options: delivery_options)
    

    更多信息请参见http://edgeguides.rubyonrails.org/action_mailer_basics.html

    【讨论】:

      猜你喜欢
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-25
      相关资源
      最近更新 更多