Jos*_* N. 7 ruby-on-rails devise devise-confirmable
好的,我已经看到很多关于自定义设计电子邮件主题的讨论,但似乎没有解决我想要的问题.目前,我的确认电子邮件主题为" 确认您的Qitch.com帐户 ".我想自定义此电子邮件主题并在其中添加用户名称的动态值,以便在用户ALEX注册帐户时,他应该获得主题为Welcome ALEX的电子邮件地址,确认您的Qitch.com帐户.我怎样才能在设计中实现这一目标?
devise.en.yml
mailer:
confirmation_instructions:
subject: 'Confirm your Qitch.com account'
reset_password_instructions:
subject: 'Reset your Qitch.com password'
unlock_instructions:
subject: 'Unlock your Qitch.com account'
Run Code Online (Sandbox Code Playgroud)
最后,如何在回复地址或地址中添加名称,目前当您收到邮件时,它说发件人:no-reply@qitch.com有没有办法我可以自定义它Qitch
谢谢
Hoa*_* Le 14
我看到答案都不够干净,所以我想在这里做一个简短的总结.
Devise您将通过以下方式覆盖其原始邮件程序方法:配置/初始化/ devise.rb
config.mailer = 'MyOverriddenMailer'
应用程序/邮寄者/ my_overridden_mailer.rb
class MyOverriddenMailer < 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 you mailer uses the devise views
def confirmation_instructions(record, token, opts={})
if record.name.present?
opts[:subject] = "Welcome #{record.name}, confirm your Qitch.com account"
else
opts[:subject] = "Confirm your Qitch.com account"
end
super
end
end
Run Code Online (Sandbox Code Playgroud)
注意:
opts选项列表:subject,to,from,reply_to,template_path,template_name.record是User模型的实例在这里设计助手以及如何:使用自定义邮件程序
class MyMailer < Devise::Mailer
def confirmation_instructions(record, opts={})
headers = {
:subject => "Welcome #{resource.name}, confirm your Qitch.com account"
}
super
end
def reset_password_instructions(record, opts={})
headers = {
:subject => "Welcome #{resource.name}, reset your Qitch.com password"
}
super
end
def unlock_instructions(record, opts={})
headers = {
:subject => "Welcome #{resource.name}, unlock your Qitch.com account"
}
super
end
end
Run Code Online (Sandbox Code Playgroud)
要么
class MyMailer < Devise::Mailer
...
...
private
def headers_for(action)
if action == :confirmation_instructions
headers = {
:subject => "Welcome #{resource.name}, confirm your Qitch.com account"
}
elsif action == :reset_password_instructions
headers = {
:subject => "Welcome #{resource.name}, reset your Qitch.com password"
}
else
headers = {
:subject => "Welcome #{resource.name}, unlock your Qitch.com account"
}
end
end
end
Run Code Online (Sandbox Code Playgroud)
并告诉设计使用您的邮件:
#config/initializers/devise.rb
config.mailer = "MyMailer"
Run Code Online (Sandbox Code Playgroud)
注意:我还没有尝试过,但它们可能对我们有帮助,请更正我的答案,如果有错误你可以编辑我的答案
| 归档时间: |
|
| 查看次数: |
4905 次 |
| 最近记录: |