How to resend dropped emails in mailgun
You can resend a message with Mailgun via their control panel and through their API. But it's only available for messages that have an associated event-type of "delivered" or "permanent fail" and are also not more than your domain's message retention period (3 days for most, I think).
API:
See their docs:
curl -s --user 'api:YOUR_API_KEY' \
https://se.api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/messages/STORAGE_URL \
-F to='[email protected]'
Control Panel:
The Logs page allows for the resending of individual messages directly within the UI. Simply login to your Mailgun account and go to the Logs tab. Click the dropdown menu cog of any qualifying message and you'll see an option in the menu called "Resend Message"
Clicking that will cause a little popup to appear where you can enter a single recipient address.
Not exactly what you want, but I had the same question and asked their support for help. I want to note their service, that I've got the answer in the next 5 minutes.
The solution: You may send a request to their API for a list of bounces and resend them manually by parsing the response JSON. It includes the error and the code which you may refer to for deciding whether to include this email address or not.
Mailgun documentation on bounces API request.
It doesn't look like Mailgun supports an easy way to resend messages, so I had to write a complicated script to do this. Here are my steps:
1) Fetch error events from https://api.mailgun.net/v3/{domain}/events?event=rejected+OR+failed
2) Inside of the error event, there is storage information that looks like this:
"storage": {
"url": "https://se.api.mailgun.net/v3/domains/{domain}messages/{some-key}",
"key": "some-key"
}
3) Use the storage URL to fetch storage details. Here you'll find all of the information about the message that you require to reconstruct the message, including: to
, from
, subject
, body-html
, reply-to
, attachments
and many more.
4) Resend the message using Mailgun's messages endpoint: https://api.mailgun.net/v3/{domain}/messages
When I have time, I'll clean up my C# implementation of this and open source it on GitHub.