[英]Mandrill / Mailchip Devise email works with mandrill_send but fails with Sidekiq
我是Mandrill的新手,所以这可能是我问题的根本原因:)-我可以通过以下示例进行操作:
https://nvisium.com/blog/2014/10/08/mandrill-devise-and-mailchimp-templates/
我不认为这是一个Devise问题,但我想我会提一下。 这是我的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:将参数传递给工作器。
不知道我在这里想念的是什么。
您可能会遇到字符串/符号冲突。 符号不能传递到Sidekiq作业。
https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.