Set Message-Id with Mandrill for bulk emails

孤人 提交于 2019-12-01 18:16:41

I ended up looping over all the recipients and generating a new Message-Id at each iteration and send one email at a time. Probably not optimal since I'm not using Mandrill bulk capability, 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)

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!