Install Message-Id with Mandrill for Bulk Email

I send emails to template-based contact lists using Mandrill. I would like to track whether the contacts answered my email address, and for this I would like to check whether the Message-Id my sent emails appears in the In-Reply-To header field of new messages.

The problem is that I need to generate and set the Message-Id manually, since Mandrill only gives me its internal _id . However, since I send emails to different contacts at the same time, I set preserve_recipients to false . But then I can install only one Message-Id , which, therefore, will not be globally unique.

Here is an example of the JSON I'm sending:

 { "from_email": " itsme@email.com ", "from_name": "Its Me", "headers": {"Message-Id": ["< 20150528161426.4265.93582@email.com >"]}, "subject": "Thesubject", "text": "Thebody", "to": [ { "email": " john@email.com ", "name": "John", "type": "to" }, { "email": " patrick@email.com ", "name": "Patrick", "type": "to" } ], "preserve_recipients": false 

}

In this case, two messages will be sent, but they will have the same Message-Id . If I do not install it, Mandrill will automatically assign it, but I cannot extract it.

Any idea what I can do? Maybe my general approach is wrong ...

+5
source share
2 answers

I completed the loop for all recipients and created a new Message-Id at each iteration and sent one email at a time. This is probably not optimal, since I am not using the Mandrill bulk features, but at least now I can store the email id.

 import email import mandrill mandrill_client = mandrill.Mandrill('YOUR_MANDRILL_KEY') for recipient in recipients: # Generate RFC 2822-compliant Message-ID header message_id = email.Utils.make_msgid() m = { "headers": {"Message-Id": [message_id], "from_email": " itsme@email.com ", "from_name": "Its Me", "subject": "The subject", "text": "The body", "to": [{"email": recipient["email"], "name": recipient["name"], "type": "to"}], "track_clicks": True, "track_opens": True } result = mandrill_client.messages.send(message=m) 
+3
source

From the mandrill documentation, you can get _id from the return value of the message.

doc

0
source

All Articles