Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何自定义Devise以使用PostMark邮件程序发送密码重置电子邮件

如何自定义Devise以使用PostMark邮件程序发送密码重置电子邮件
EN

Stack Overflow用户
提问于 2011-04-15 16:13:32
回答 3查看 23.8K关注 0票数 19

我正在尝试使用PostMarkApp和Rails get (postmark-railspostmark-gemmail)将我系统的所有电子邮件通知整合到一个保护伞下。我已经成功地创建了一个邮件程序,可以处理购物收据的发送,但我还无法收到忘记密码的电子邮件。我的开发日志显示Devise发送了消息,但我的收件箱中没有收到电子邮件,PostMark积分也没有减少。

通过我的PostMark帐户发送Devise的邮件的最好或最简单的方式是什么?

来自config/environments/development.rb的代码片段

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
config.action_mailer.delivery_method      = :postmark
config.action_mailer.postmark_settings    = { :api_key => "VALID_API_KEY_WAS_HERE" }
config.postmark_signature                 = VALID_POSTMARK_SIGNATURE_WAS_HERE

使用邮戳我的邮件程序

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class Notifier < ActionMailer::Base
  # set some sensible defaults
  default :from => MyApp::Application.config.postmark_signature

  def receipt_message(order)
    @order = order
    @billing_address = order.convert_billing_address_to_hash(order.billing_address)

    mail(:to => @order.user.email, :subject => "Your Order Receipt", :tag => 'order-receipt', :content_type => "text/html") do |format|
      format.html
    end
  end
end

编辑:我的问题的解决方案在下面

通过让我的Notifier邮件程序扩展Devise::Mailer并指定Devise在config/initializers/devise.rb中使用我的通告程序作为邮件程序,解决了这个问题

来自config/initializers/devise.rb代码片段

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# Configure the class responsible to send e-mails.
config.mailer = "Notifier"

我的通告邮件程序now

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class Notifier < Devise::Mailer
  # set some sensible defaults
  default :from => MyApp::Application.config.postmark_signature

  # send a receipt of the Member's purchase
  def receipt_message(order)
    @order = order
    @billing_address = order.convert_billing_address_to_hash(order.billing_address)

    mail(:to => @order.user.email, :subject => "Your Order Receipt", :tag => 'order-receipt', :content_type => "text/html") do |format|
      format.html
    end
  end

  # send password reset instructions
  def reset_password_instructions(user)
     @resource = user
     mail(:to => @resource.email, :subject => "Reset password instructions", :tag => 'password-reset', :content_type => "text/html") do |format|
       format.html { render "devise/mailer/reset_password_instructions" }
     end
   end
end
EN

回答 3

Stack Overflow用户

发布于 2011-09-07 17:55:36

使用最新版本的Devise,上面的方法对我没有帮助。这是我的解决方案。

在config/application.rb中:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
config.action_mailer.delivery_method   = :postmark
config.action_mailer.postmark_settings = { :api_key => "your-API-key-here" }

在config/initializers/devise.rb中:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
config.mailer = "UserMailer" # UserMailer is my mailer class

在app/mailers/user_mailer.rb中:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class UserMailer < ActionMailer::Base
  include Devise::Mailers::Helpers

  default from: "default@mydomain.com"

  def confirmation_instructions(record)
    devise_mail(record, :confirmation_instructions)
  end

  def reset_password_instructions(record)
    devise_mail(record, :reset_password_instructions)
  end

  def unlock_instructions(record)
    devise_mail(record, :unlock_instructions)
  end

  # you can then put any of your own methods here
end

最后,确保您已经生成了自定义的设计视图

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
rails generate devise:views

并将电子邮件模板从app/views/devise/mailer/移动到app/views/user_mailer/

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
mv app/views/devise/mailer/* app/views/user_mailer/
票数 20
EN

Stack Overflow用户

发布于 2011-12-02 22:56:54

如果您还想在邮戳标题中指定‘tag’,则必须在邮件程序中执行此操作:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  # this override method is from Devise::Mailers::Helpers
  def headers_for(action)
    headers = {
      :subject        => translate(devise_mapping, action),
      :from           => mailer_sender(devise_mapping),
      :to             => resource.email,
      :template_path  => template_paths,
      :tag            => action.dasherize # specify the tag here
    }
    if resource.respond_to?(:headers_for)
      headers.merge!(resource.headers_for(action))
    end
    unless headers.key?(:reply_to)
      headers[:reply_to] = headers[:from]
    end
    headers
  end
票数 1
EN

Stack Overflow用户

发布于 2011-05-16 20:12:21

我还必须为设计生成视图,并将邮件模板复制到我的邮件程序的正确位置。像这样的东西-

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
rails generate devise:views
cp app/views/devise/mailer/* app/views/notification_mailer/
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5679571

复制
相关文章
photoshop_python_api: 最好用的photoshop python api
在影视或者游戏的制作中我们多多少少会用到Photoshop, 但是Photoshop原生不支持Python, 这样会导致我们平常在做流程的时候打通其他环节到Photoshop的难度就加到了。如果买了Ftrack或者Shotgun的公司他们自带的工具链就支持通过python去操作Photoshop除此之外就通过Python的第三方库comtypes去操作Photoshop
用户9897904
2022/07/14
4.8K3
photoshop_python_api: 最好用的photoshop python api
Python实现简单的API
get方法 代码实现 # coding:utf-8 import json from urlparse import parse_qs from wsgiref.simple_server import make_server # 定义函数,参数是函数的两个参数,都是python本身定义的,默认就行了。 def application(environ, start_response): # 定义文件请求的类型和当前请求成功的code start_response('200 OK', [
py3study
2020/01/13
9770
Python win32api_python api文档
本文整理汇总了Python中win32api.SetCursorPos方法的典型用法代码示例。如果您正苦于以下问题:Python win32api.SetCursorPos方法的具体用法?Python win32api.SetCursorPos怎么用?Python win32api.SetCursorPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块win32api的用法示例。
全栈程序员站长
2022/11/10
1.1K0
saltstack python api
client.cmd('SN2016-02-04','cmd.run',['free -m'])
py3study
2020/01/03
8610
GoPro API for Python
用于Python的非官方GoPro API库-通过WiFi连接到GoPro摄像机。
云深无际
2020/08/11
1K0
Python API 2.0
Python API 2.0 从2.0的事情开始更复杂一些,但是你会得到更多离散和可读的类:
py3study
2020/01/12
7170
Python Elasticsearch api
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。下面介绍了利用Python API接口进行数据查询,方便其他系统的调用。
py3study
2020/02/21
4.5K0
Python Elasticsearch api
Python常用API
Python 截取字符串使用 变量[头下标:尾下标],就可以截取相应的字符串,其中下标是从0开始算起,可以是正数或负数(从右向左),下标可以为空表示取到头或尾。
Helloted
2022/06/06
9120
ArcGIS API for Python
是一个强大的 Python 库,用于制图、空间分析、数据科学、地理空间 AI 和自动化。
陈南GISer
2022/04/04
8020
ArcGIS API for Python
Python实现简单的API接口
get方法 代码实现 # coding:utf-8 import json from urlparse import parse_qs from wsgiref.simple_server import make_server # 定义函数,参数是函数的两个参数,都是python本身定义的,默认就行了。 def application(environ, start_response): # 定义文件请求的类型和当前请求成功的code start_response('200 OK', [
py3study
2020/01/09
6.9K0
Python实现简单的API接口
jenkins python api与json api不同
查看jenkins的python api与json api,感觉两者相差不多,但还是有所区别,所以用BeyondCompare进行对比分析。
donghui
2019/04/19
7910
jenkins python api与json api不同
pytorch的python API略读--Sequential/ModuleList/ModuleDict
torch.nn.Sequential:序列容器,顾名思义,就是将构造函数中的子模块会按照你定义的序列顺序被添加到模块中。这里有个注意的小点,要注意区分Sequential和torch.nn.ModuleList,后者就是一个简单的列表,里面的元素是模块,但是模块之间是孤立的,前者则是互相连通的模块。还是以上面的网络模块为例,使用Sequential可以实现快速搭建:
用户9875047
2022/07/04
2930
python3 Zabbix监控-api的使用-python
1、 获得认证密钥 auth user and password data = json.dumps( { "jsonrpc": "2.0", "method": "user.login", "params": { "user": "Admin", "password": "zabbix" }, "id": 0 }) 2、 获取zabbix所有的主机组 request json data = json.dumps( { "jsonrpc":"2.0", "method":"h
98k
2018/04/11
1.8K0
Python生成图像API
常用的图像处理技术有图像读取,写入,绘图,图像色彩空间转换,图像几何变换,图像形态学,图像梯度,图像边缘检测,图像轮廓,图像分割,图像去噪,图像加水印以及修复水印等
KINGLIFE
2022/04/20
6400
Python Gitlab Api 使用
简述 公司使用gitlab 来托管代码,日常代码merge request 以及其他管理是交给测试,鉴于操作需经常打开网页,重复且繁琐,所以交给Python 管理。 官方文档 安装 pip install python-gitlab 环境: py3 DEMO # -*- coding: utf-8 -*- __Author__ = "xiewm" __Date__ = '2017/12/26 13:46' """ gitlab 经常使用到的api DOC_URL: ht
py3study
2020/01/06
6.1K0
Python 调用cobbler API
目前BootAPI 已经不再推荐在cobbler 2.0中使用,官方推荐使用使用XMLRPC 
py3study
2020/01/10
2.1K0
python调用java API
JPype的下载地址:https://pypi.python.org/pypi/JPype1 JPype的帮助文档:http://jpype.readthedocs.io/en/latest/
py3study
2020/01/08
2.1K0
⚠️ Python编写简易API
本文约550字,将耗费您约4⃣️分钟~ 所有的操作,仅在mac系统上实操过 前期准备 创建一个虚拟环境: $ mkdir flask_restful $ cd flask_restful $ python3 -m venv venv 激活虚拟环境: $ . venv/bin/activate 虚拟环境退出: $ deactivate 安装flask和flask_restful: $ pip install flask $ pip install flask_restful 项目接口模拟 在项目的根目录下
Jimmy_is_jimmy
2022/03/10
8990
python查看api文档
python –m pydoc –p 1234 浏览器中访问http://localhost:1234/ 就可以打开python及集成的其他库的api
py3study
2020/01/09
1.2K0
pytorch的python API略读--tensor(六)
torch.permute:返回输入tensor的一个维度层次的置换,不知道置换的概念,可以搜索下群论中的置换群的定义及置换的记号。用法如下:
用户9875047
2022/07/04
2750

相似问题

如何在xpath相同的情况下识别selenium中的元素

30

使用Xpath (selenium <iframe> )定位<iframe>中的HTML元素

22

绝对路径: Selenium Xpath无法识别元素

20

如何使用Xpath选择iframe中的元素?

11

使用xpath识别元素的困难

20
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文