evendis / mandrill-rails

Webhook processing and event decoration to make using Mandrill with Rails just that much easier
MIT License
288 stars 36 forks source link

How to identify mandrill webhook #14

Closed vladCovaliov closed 10 years ago

vladCovaliov commented 10 years ago

Sorry for not asking a question related to the gem, but I don't have any other solutions :) . Maybe at some point it will help others also .

I have a Rails 4 application which sends emails using Mandrill. I am trying to detect weather a mail was opened or bounced, so I am using webhooks for this. I successfully receive the webhooks, but I can't tell which of them identify a particular email from my database.

I've tried using this

  def send_message(email)

    mail( from: ...,
          to: ...,
          subject: ...)

    headers["X-MC-AutoHtml"] = "true"
    headers["X-MC-Track"] = "opens"
    headers['X-MC-MergeVars'] = { "id" => some_id }.to_json
  end

but I'm not sure if I'm supposed to receive the X-MC-MergeVars back ( this is what I've understand from the docs)

Unfortunately, it's not working.

Do you have any ideas or an alternative solution? Thanks

vladCovaliov commented 10 years ago

I've figured it out by myself.

This is the line that needs to be there

headers['X-MC-Metadata'] = { "user_id" => user.id}.to_json

Here are the further details: http://help.mandrill.com/entries/21786413-Using-Custom-Message-Metadata

Hope it helps someone since it cost me several hours :+1: