我是 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 worker (MandrillEmail.perform_async(选项)),它会失败并显示:
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和消息>to>email:参数被传递给工作线程。
不知道我在这里错过了什么。
您可能遇到了字符串/符号冲突。 符号不能传递给 Sidekiq 作业。
https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple