加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 01:19:46 所属栏目:百科 来源:网络整理
导读:我正在尝试在Rails 4中创建一个应用程序. 在过去的3年里,我一直在努力弄清楚设计/ omniauth(我仍然试图让它发挥作用). 当我试图找到通过这个问题的意愿时,撇开主要问题,我试图用Mandrill设置电子邮件. 我找到了这个教程,我试图遵循:https://nvisium.com/blo
我正在尝试在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读