简体   繁体   English

即时更改带有凭据的http_basic_authenticate_

[英]Change http_basic_authenticate_with credentials on fly, rails

I need that user can change ActionMailer settings on fly, without server restarting. 我需要用户可以在不重新启动服务器的情况下即时更改ActionMailer设置。 I'm tryin do that on my mailer class 我正在邮件班上尝试

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

end 结束

But changes take effect only after server restarting. 但是更改仅在服务器重新启动后生效。

Update 更新

Thanks to Anthony L change smtp settings dynamically already solved, but i have another question. 多亏了Anthony L,动态地更改smtp设置已经解决了,但是我还有另一个问题。

http_basic_authenticate_with name: login, password: password

How dynamically change authentication credentials for this case? 在这种情况下如何动态更改身份验证凭据?

Instead of changing the smtp_settings directly, use delivery_method_options on the mail method. 与其直接更改smtp_settings,不如对mail方法使用delivery_method_options。 For instance: 例如:

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)

See http://edgeguides.rubyonrails.org/action_mailer_basics.html for more information. 有关更多信息,请参见http://edgeguides.rubyonrails.org/action_mailer_basics.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM