在fly,rails上更改http_basic_authenticate_with凭据

问题描述 投票:1回答:1

我需要用户可以在运行时更改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个回答
2
投票

不要直接更改smtp_settings,而是在mail方法上使用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

© www.soinside.com 2019 - 2024. All rights reserved.