获取在 Mailgun 中打开或点击的电子邮件的主题

Get subject of opened or clicked email in Mailgun

我已经设置了我的 Mailgun 域来跟踪我的 Laravel 应用程序发送的电子邮件的打开和点击。

现在我想设置 webhooks 以接收这些事件的通知。

特别是,我很想知道事件类型(例如打开、点击、失败等)、主题、收件人电子邮件地址,最好是邮件正文(虽然不是必需的)。对于 'click' 事件,我还想查看被单击的 link 的 URL。

我看到 Event data get sent by the webhook, and unlike Amazon SES 的哪些字段,Mailgun 的 webhook 似乎包括电子邮件主题或正文。

webhook 提供如下数据:

"message": {
    "headers": {
        "message-id": "f9bxxxxx1e30e7278f5fe75f50741fb3@swift.generated"
    }
}

所以在我看来,我需要以某种方式去我的应用程序中发送电子邮件的每个地方并添加额外的功能以将电子邮件的详细信息以及 保存到我自己的数据库中每条消息发送后立即。

然后,当接收到 webhook 时,我会在我自己的数据库中搜索消息 ID,并可以看到我存储的主题和正文。

这似乎是一个可怕的麻烦和糟糕的设计,特别是考虑到其他服务(例如 SES)会在 webhook 中为我提供电子邮件主题。

有没有更简单的方法让我知道打开或点击了哪些 封电子邮件(当我收到有关打开或点击事件的 Mailgun webhook 时)?

(我是不是误会了什么,或者我真的需要改造我的整个应用程序以利用 Mailgun 中的开放式跟踪吗?)

这是我从help@mailgun.com收到的官方回复:

Your assumption is correct, the Opened and Clicked events do not contain the Subject line for the message that originated the tracking event.

Currently, the Clicked and Open tracking links do not track the Subject line for the message it is tracking. The tracking links encode the Message-ID, Recipient, Domain, recipient variables, and other proprietary data that link the tracking address back to your account. Adding additional data to the tracking links would cause the link to increase the link's length and potentially label the link as suspicious or "spammy" by recipient spam filters.

At this time, there are no plans to change the behavior of Clicked and Opened events, but we have a page set up to receive feedback/feature requests at http://mailgun.uservoice.com/. Feel free to submit this request. Other users can upvote the request, and our developers will review the requests and take them into consideration for future versions of our product.

他们的这个借口令人沮丧,因为这是一个谎言:URL 的长度与他们是否可以在 webhook 中报告主题(以及电子邮件的任何其他属性)无关.

Mailgun 期望其用户做的正是 Mailgun 可以 做但选择不做的事情:在数据库中将额外数据与消息 ID 一起存储,然后使用该消息-id of the trackable link 为 webhook 目的获取额外数据。

我将改用 Mailgun 以外的提供商,尤其是现在我 了解到 Hotmail、MSN 和 Live.com 都拒绝我的 Mailgun 电子邮件。

Mailgun 允许将变量附加到消息中并将它们作为 webhook 负载的一部分接收回来。例如,您可以像下面这样发送主题。

X-Mailgun-Variables: {"subject": "your subject"}

查看 Mailgun 用户手册:https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages

请参阅以下部分:将数据附加到消息