使用Mandrill为大宗电子邮件设置Message-Id [英] Set Message-Id with Mandrill for bulk emails

查看:111
本文介绍了使用Mandrill为大宗电子邮件设置Message-Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mandrill根据模板向联系人列表发送电子邮件.我想跟踪联系人是否回复了我的电子邮件,为此,我想检查已发送电子邮件的Message-Id是否出现在新邮件的In-Reply-To标头字段中.

I am sending emails to lists of contacts based on templates using Mandrill. I would like to track if the contacts have replied to my email and, to do so, I would like to check whether the Message-Id of my sent emails appears in the In-Reply-To header field of new messages.

问题在于我必须手动生成和设置Message-Id,因为Mandrill仅给了他们内部的_id.但是,由于我要同时向各个联系人发送电子邮件,因此将preserve_recipients设置为false.但是然后我只能设置一个Message-Id,因此它将成为不是全局唯一的.

The problem is that I have to generate and set the Message-Id manually since Mandrill only gives me their internal _id. However, since I am sending emails to various contacts at the same time, I set preserve_recipients to false. But then I can only set one Message-Id, which will therefore become not globally unique.

这是我要发送的示例JSON:

Here is an example JSON that 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

}

在这种情况下,将发送两条消息,但是它们将具有相同的Message-Id.如果我没有设置,Mandrill将自动分配一个,但是这样我将无法检索它.

In this case, two messages will be sent, but they'll have the same Message-Id. If I don't set it, Mandrill will automatically assign one, but then I can't retrieve it.

任何想法我能做什么?也许我的整体方法不正确...

Any idea what I could do ? Maybe my whole approach is incorrect...

推荐答案

我最终遍历了所有收件人,并在每次迭代中生成了一个新的Message-Id,并一次发送一封电子邮件.可能不是最佳选择,因为我没有使用Mandrill批量功能,但至少现在我可以存储电子邮件ID.

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)

这篇关于使用Mandrill为大宗电子邮件设置Message-Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆