Get subject of opened or clicked email in Mailgun

2019-07-25 03:11发布

问题:

I've set up my Mailgun domain to track the opens and clicks of emails sent by my Laravel app.

Now I want to set up webhooks to be notified of those events.

In particular, I'd love to know the event type (e.g. open, click, failed, etc), subject, recipient email address, and ideally the body of the message (although not necessary). For 'click' events, I also want to see the URL of the link that was clicked.

I see which fields of Event data get sent by the webhook, and unlike Amazon SES, Mailgun's webhooks do not seem to include the email subject or body.

The webhook provides data like this:

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

So it seems to me that I'd somehow need to go to every place within my app that sends an email and add extra functionality to save to my own database the details of the email along with the unique Mailgun message-id of every message right after it has been sent.

Then, when receiving webhooks, I'd search my own database for the message-id and could see the subject and body that I'd stored.

This seems like a terrible hassle and poor design, especially given that other services (such as SES) would provide the email subject for me in the webhook.

Is there some easier way for me to know which emails were opened or clicked (when I receive a Mailgun webhook about an open or click event)?

(Am I misunderstanding something, or would I really need to revamp my entire app to take advantage of open tracking in Mailgun?)

回答1:

Here is the official response I received from 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.

This excuse of theirs is frustrating because it's a lie: the length of the URL has nothing to do with whether or not they could report the subject (and any other attribute of the email) in the webhook.

What Mailgun is expecting its users to do is exactly what Mailgun could do but chooses not to: store extra data alongside the message-id in a database and then use the message-id of the trackable link to fetch that extra data for webhook purposes.

I will switch to a provider other than Mailgun, especially now that I also learned that Hotmail, MSN, and Live.com are all rejecting my Mailgun emails.