简体   繁体   中英

Mandrill / Mailchip Devise email works with mandrill_send but fails with Sidekiq

I am new to Mandrill so this may be the root cause of my issue :) - I have it working from this example:

https://nvisium.com/blog/2014/10/08/mandrill-devise-and-mailchimp-templates/

I don't think it's a Devise issue but I figured I would mention it. Here is my DeviseMailer code:

  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

This works - I get my email and the templates work etc.

Now if I move the logic to a SideKiq worker (MandrillEmail.perform_async(options)) it fails with:

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."}]}}

I added :template_name => "Invitation" but that doesn't work. My sidekiq monitor clearly shows both the template_name and message>to>email: params being passed into the worker.

Not sure what I am missing here.

Likely you are running into a string/symbol conflict. Symbols cannot be passed to Sidekiq jobs.

https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM