When a user unsubscribes from an email in gmail, it seems gmail sends an email to the sender with:
`subject`: "unsubscribe"
`body`: "This message was automatically generated by Gmail."
`to`: u+(somesuperlongrandomstring)@domain.tld
`from`: (Email of user who unsubscribed)
Similarly, when a user unsubscribes from an email in Apple Mail, it seems Apple Mail sends an email to the sender with:
`subject`: (blank)
`body`: Apple Mail sent this email to unsubscribe from the message "(Subject of email unsubscribed from)".
`to`: u+(somesuperlongrandomstring)@domain.tld
`from`: Email of user who unsubscribed
We use mailgun to handle unsubscribes already, but as of 28th March 2022, these emails from both providers now make it through our email routing.
Does anyone know how to tell gmail or Apple Mail to not send these emails? They are redundant because mailgun is already handling the unsubscribe using the list-unsubscribe
header as you'd expect.
Alternatively, does anyone know how to set up Mailgun so these messages aren't passed through routes?
So Mailgun didn't provide any help, sadly. But looking through their documentation, and the headers of these emails, it seems possible to use their Routes to hide the emails completely.
The three clues are:
X-Apple-Unsubscribe:true
As such, you can create a route as such to capture and discard these emails using a custom route
with the raw expression
set to:
match_recipient("u\+(.*)@domain.tld") and (match_header("X-Apple-Unsubscribe", "true") or match_header('subject', 'unsubscribe'))
It's sad that Mailgun stopped doing this themselves, but at least there is a solution with their tooling!
EDIT (May 2023): Sadly it seems yahoo send through these unsubscribe emails, with an empty subject and no header to identify them. It also seems that Mailgun don't allow pattern matching on the empty string - so you can't check for an empty subject. A such, the best solution seems to be:
match_recipient("u\+(.*)@domain.tld")
You should clearly make sure you don't get any legitimate emails in that format!