【问题标题】:How to set custom bcc/to field for Devise Mailer emails?如何为 Devise Mailer 电子邮件设置自定义密件抄送/收件人字段?
【发布时间】:2016-02-19 03:13:01
【问题描述】:

我想在通过 Devise 发送的所有电子邮件的 to/bcc 标头中包含我的用户的名字和姓氏。

我看了这个https://github.com/plataformatec/devise/blob/master/lib/devise/mailers/helpers.rb#L28

似乎 Devise 在模板中也将 to 字段分配为 @email。我将如何覆盖标头,以便使用 to/bcc 标头 "FirstName LastName <email@example.com>" 发送电子邮件?

【问题讨论】:

    标签: ruby-on-rails devise


    【解决方案1】:

    我会先看看How-To:-Use-custom-mailer

    要使用自定义邮件程序,请创建一个扩展 Devise::Mailer 的类,如下所示:

    class MyMailer < Devise::Mailer   
      helper :application # gives access to all helpers defined within `application_helper`.
      include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
      default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views
    end
    

    然后,在您的 config/initializers/devise.rb 中,将 config.mailer 设置为 "MyMailer"

    def confirmation_instructions(record, token, opts={})
      opts[:to] = 'fname lname<email@example.com>'
      opts[:bcc] = 'fname lname<email@example.com>'
      super
    end
    

    我希望这对您有所帮助并为您指明正确的方向

    【讨论】:

      猜你喜欢
      • 2011-07-24
      • 1970-01-01
      • 2011-02-01
      • 2012-09-13
      • 2016-02-08
      • 2019-01-01
      • 2013-12-22
      • 1970-01-01
      • 2015-12-19
      相关资源
      最近更新 更多