我正在尝试弄清楚如何设置我的Rails 4应用程序,以便设计器使用Postmark模板通过Postmark发送邮件。
我的gem文件中有postmark-rails gem。
我已经把所有的东西都准备好了,除了我想不出怎么给邮戳加上确认令牌。
在邮戳中,我有这个模板:
To get started, please confirm your account below:
action_url_Value我不知道如何将下面这行代码放入模板中,而不是放入action url值中:
<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></div>我已经在我的初始化器/devise.rb中添加了以下内容:
config.mailer = 'PostmarkDeviseMailer'在postmark_devise_mailer.rb中,我有:
class PostmarkDeviseMailer < ActionMailer::Base
include Devise::Mailers::Helpers
def message
mail(
:subject => 'Hello from Postmark',
:to => 'sender@address.com',
:from => 'sender@address.comm',
:html_body => '<strong>Hello</strong> dear Postmark user.',
:track_opens => 'true')
end
end
default from: "sender@address.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接下来的步骤对我来说不太清楚。有没有人想出了如何使用邮戳模板作为设计交易电子邮件的邮件?
发布于 2016-05-06 09:15:15
Postmark help desk的回应是:不幸的是,Postmark模板不能很好地适应传统的Rails生态系统。有关详细信息,请参阅我的回复:
https://github.com/wildbit/postmark-rails/issues/53
总而言之,通过将Postmark API与Postmark模板一起使用,您可能会取代ActionMailer,但将它们混合在一起会带来巨大的挑战。不幸的是,我们从来没有尝试过Devise的"ActionMailer-free“方法,所以我不能在这里帮助你。除非您有充分的理由不这样做,否则我建议使用ActionMailer模板,并使用postmark-rails gem作为交付适配器。众所周知,这种方法与Devise配合使用效果很好。如果你有任何问题请告诉我。
发布于 2020-07-19 03:29:21
你需要做的第一件事是在app/mailers中创建一个自定义邮件程序在这个例子中它是user_mailer.rb如果你正在阅读这个答案,我假设你们两个都有一个邮戳帐户,如果没有在这里抓取一个:Postmark Registration和我假设你已经选择了一个模板和布局。
需要记住的一个重要事项是确保为模板分配了别名。这可以在模板标题上方的小链接中找到,该链接以灰色小文本显示。
self.template_model中的项目是100%可定制的,并且在布局/模板编辑器中显示为:{{product_name}}。
class UserMailer < Devise::Mailer
include PostmarkRails::TemplatedMailerMixin
helper :application
include Rails.application.routes.url_helpers
include Devise::Controllers::UrlHelpers
default from: 'from_you@something.com'
default reply_to: 'support@hammer-lane-industries.com' # Optional
def confirmation_instructions(record, token, opts={})
@admin = record
@token = token
# this will pass the data via the postmark-api to your template / layout these fields are 100% customizable and can be cahnged in your template / layout
self.template_model = { product_name: 'your product',
username: @user.username,
email: @user.email,
confirmation_url: user_confirmation_url(@resource, confirmation_token: @token, subdomain: 'add subdomain here if needed'),
login_url: login_root_url(subdomain: 'add subdomain here if needed'),
trial_length: '14-days',
sender_name: 'What ever you want',
action_url: user_confirmation_url(@resource, confirmation_token: @token, subdomain: 'add subdomain here if needed'),
parent_company_name: 'Your company name',
company_address: 'Your address'}
mail to: @admin.email, postmark_template_alias: 'devise_user_confirmation'
end
end用解锁和密码邮件程序冲洗和重复,你所需要知道的就是你将要发送令牌到的urls。
完成这一切的:
您将需要向您的devise资源模型添加一个小块,在本例中我使用了user.rb
class User < ApplicationRecord
devise :database_authenticatable, :confirmable,
:recoverable, :rememberable, :validatable,
:timeoutable, :trackable
def devise_mailer
UserMailer # Must match your mailer class
end
end完成此操作后,重新启动rails服务器,并开始尝试!
我希望这能帮助您将邮戳模板挂接到Devise mailers中
https://stackoverflow.com/questions/37039500
复制相似问题