ruby-on-rails – Rails 4,Devise和Mandrill电子邮件

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails 4,Devise和Mandrill电子邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在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 confirmation_instructions(record,token,opts={})
    # code to be added here later
  end

  def reset_password_instructions(record,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,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

上述内容与本教程中的内容之间存在差异:

在我的邮件黑猩猩mandrill模板中,我有:

<a href="*|password_reset_link|*">Change my password </a>

当我收到重置说明的电子邮件时,我会看到更改密码表单的带下划线的链接,其中显示“更改密码旁边的密码”.我想’将我的密码更改为隐藏链接文本的标签’.

谁能看到我做错了什么?

解决方法

这是我创建自定义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,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
Add dynamic value in devise email subject

猜你在找的Ruby相关文章