【发布时间】:2016-06-05 23:05:41
【问题描述】:
我是 Mandrill 的新手,所以这可能是我的问题的根本原因 :) - 我从这个例子中得到了它:
https://nvisium.com/blog/2014/10/08/mandrill-devise-and-mailchimp-templates/
我不认为这是一个设计问题,但我想我会提到它。这是我的 DeviseMailer 代码:
def invitation_instructions(record, token, opts={})
options = {
:subject => "Subject",
:from_name=> "From",
:email => record.email,
:global_merge_vars => [
{ name: 'invite_name', content: "Invited By" },
{ name: 'invite_email', content: "Invited By Email" },
{ name: 'invite_company', content: "Company Name" },
{ name: 'invitation_url', content: root_url(:invitation_token => token) } #accept_invitation_url(record, :invitation_token => token)
],
:template => "Invitation",
:template_name => "Invitation"
}
mandrill_send options
#MandrillEmail.perform_async(options)
end
def mandrill_send(opts={})
message = {
:subject=> "#{opts[:subject]}",
:from_name=> "#{opts[:from_name]}",
:from_email=>"do-not-reply@xxxxx.com",
:to=>
[{"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
这行得通 - 我收到了我的电子邮件和模板工作等。
现在,如果我将逻辑移至 SideKiq 工作器 (MandrillEmail.perform_async(options)),它会失败并显示:
Mandrill::ValidationError: Validation error: {"template_name":"Sorry, this field can't be left blank.","message":{"to":[{"email":"Sorry, this field can't be left blank."}]}}
我添加了:template_name => "Invitation",但这不起作用。我的 sidekiq 监视器清楚地显示了 template_name 和 message>to>email: 参数正在传递给 worker。
不确定我在这里缺少什么。
【问题讨论】:
标签: ruby-on-rails devise mailchimp sidekiq mandrill