Rails 4,Devise& Mandrill电子邮件 [英] Rails 4, Devise & Mandrill emails
问题描述
我试图在Rails 4中制作一个应用程序。
在过去的3年中,我一直在努力找出设计/ omniauth(我是仍然试图让它工作)。
除了主要问题之外,我尝试找到通过这种方式生活的意愿,我试图设置电子邮件Mandrill。
我发现这个教程,我试图遵循:https://nvisium.com/blog/2014/10/08/mandrill-devise-and-mailchimp-templates/
我有一个名为mandrill_devise_mailer.rb的邮件程序
class MandrillDeviseMailer< Devise :: Mailer
def confirm_instructions(record,token,opts = {})
#此处添加的代码
end
def reset_password_instructions (记录,令牌,opts = {})
options = {
:subject => 重设密码,
:email => record.email,
:global_merge_vars => [
{
name:password_reset_link,
#content:http://www.example.com/users/password/edit?reset_password_token=#{token}
content:http://www.cr.com/users/password/edit?reset_password_token=#{token}
},
{
名称:PASSWORD_RESET_REQUEST_FROM,
content:record.full_name
}
],
:template => 忘记密码
}
mandrill_send选项
end
def unlock_instructions(record,token,opts = {})
#要添加的代码以后
end
def mandrill_send(opts = {})
message = {
:subject => #{opts [:subject]},
:from_name => 重置说明,
#:from_email =>example@somecorp.com,
:from_email => [PROD_WELCOME],
:to =>
[{name=>#{opts [:full_name]},
email=>#{opts [:email]},
type =>to}],
:global_merge_vars => opts [:global_merge_vars]
}
sending = MANDRILL.messages.send_template opts [:template],[],message
rescue Mandrill :: Error => e
Rails.logger.debug(#{e.class}:#{e.message})
raise
end
end
上述内容与本教程中所做的不同之处在于:
在我的邮件黑猩猩mandrill模板,我有:
< a href =* | password_reset_link | *>更改我的密码< / a>
当我收到重新设置说明的电子邮件时,我会收到一个下划线的更改密码表单链接,它说在我旁边更改我的密码。我想要将我的密码更改为隐藏链接文本的标签。
任何人都可以看到我做错了什么?
这是我如何创建自定义DeviseMailer
class MyDeviseMailer< Devise :: Mailer
/ pre>
default template_path:'devise / mailer'#以确保您的邮件程序使用设计视图
def reset_password_instructions(record,token,opts = {})
opts ['from_email'] =donotreply@mywebsite.com
opts ['from_name'] =密码重置
#Rails.logger.mail.inforeset_password_instructions#{record.to_json} \\\
#{token.to_json} \\\
#{opts.to_json}
super
end
end
https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer 和
在设计电子邮件主题中添加动态值I'm trying to make an app in Rails 4.
For the past 3 years, I've been struggling to figure out devise/omniauth (I am still trying to get it to work).
Stepping aside from the main problems while I try and find the will to live through this, I've tried to setup emails with Mandrill.
I found this tutorial, which I am trying to follow along: https://nvisium.com/blog/2014/10/08/mandrill-devise-and-mailchimp-templates/
I have a mailer called mandrill_devise_mailer.rb
class MandrillDeviseMailer < Devise::Mailer def confirmation_instructions(record, token, opts={}) # code to be added here later end def reset_password_instructions(record, token, opts={}) options = { :subject => "Reset your password", :email => record.email, :global_merge_vars => [ { name: "password_reset_link", # content: "http://www.example.com/users/password/edit?reset_password_token=#{token}" content: "http://www.cr.com/users/password/edit?reset_password_token=#{token}" }, { name: "PASSWORD_RESET_REQUEST_FROM", content: record.full_name } ], :template => "Forgot Password" } mandrill_send options end def unlock_instructions(record, token, opts={}) # code to be added here later end def mandrill_send(opts={}) message = { :subject=> "#{opts[:subject]}", :from_name=> "Reset Instructions", # :from_email=>"example@somecorp.com", :from_email=>["PROD_WELCOME"], :to=> [{"name"=>"#{opts[:full_name]}", "email"=>"#{opts[:email]}", "type"=>"to"}], :global_merge_vars => opts[:global_merge_vars] } sending = MANDRILL.messages.send_template opts[:template], [], message rescue Mandrill::Error => e Rails.logger.debug("#{e.class}: #{e.message}") raise end end
The differences between the above and what they have done in the tutorial are:
In my mail chimp mandrill template, I have:
<a href="*|password_reset_link|*">Change my password </a>
When I receive the email to reset the instructions, I get an underlined link to the change password form, which says 'change my password next to it. I want 'change my password to be the label which conceals the link text'.
Can anyone see what I've done wrong?
解决方案Here is how I created custom DeviseMailer
class MyDeviseMailer < Devise::Mailer default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views def reset_password_instructions(record, token, opts={}) opts['from_email'] = "donotreply@mywebsite.com" opts['from_name'] = "Password Reset" #Rails.logger.mail.info "reset_password_instructions #{record.to_json} \n #{token.to_json} \n #{opts.to_json}" super end end
https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer and Add dynamic value in devise email subject
这篇关于Rails 4,Devise& Mandrill电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!