How to resend dropped emails in mailgun
Asked Answered
M

4

7

How to resend dropped emails in mailgun?

I am using mailgun to send mails in my application,but some mails are dropped. Is there any method to resend the dropped mails?

Margy answered 16/9, 2015 at 14:10 Comment(0)
C
9

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"

enter image description here

Clicking that will cause a little popup to appear where you can enter a single recipient address.

enter image description here

Choplogic answered 6/7, 2017 at 18:15 Comment(4)
There's no option in the new UI. see https://mcmap.net/q/1406018/-how-to-resend-dropped-emails-in-mailgunDart
@DaniilMashkin It's still there, they just moved it to the right side of the table. Make sure you're looking at qualifying messages, though. They hide options in the dropdown if they are not applicable to the message related to the selected event.Choplogic
Note that the the Mailgun docs are wrong up until 2020-12-18 (verified by their support team). Instead of appending the STORAGE_URL as is to the API endpoint, you just post to the STORAGE_URL itself: curl -s --user 'api:YOUR_API_KEY' \ STORAGE_URL \ -F to='[email protected]'Mitchelmitchell
Here's a ruby script I put together to assist in resending multiple failures, if helpful for anyone else: gist.github.com/parterburn/6f2332a815f6616131e6d74254c40012Lexicon
U
6

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.

Urgent answered 15/12, 2015 at 12:14 Comment(4)
Recently because of some credit card issue, our transnational mails got rejected, how could this be re-sended is not in their docs ? do they store mail content in their servers ? it would be better to add some code snippet to your post explaining how you did it.Juvenilia
@stom it would be better to ask unrelated questions as separate question, not a comment. What code you wish to add? A foreach loop in unknown language?Urgent
@SergeyTelshevsky I believe what stom is asking for is how you would resend messages. I'm also interested in this answer. Did you parse the JSON and then re-compose a new message with the content from the JSON? Or were you able to resent that message through a special endpoint or something like that (using maybe the message ID)? I can't find such a special endpoint so I'm assuming the former, but that gets complicated with file attachments and so on. The latter would be much nicer.Merely
@stom I just posted my solution to this problem here: https://mcmap.net/q/1406018/-how-to-resend-dropped-emails-in-mailgun. I hope this works for you.Merely
M
5

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.

Merely answered 4/1, 2017 at 10:58 Comment(3)
Appreciate your efforts, good to know that you have found a solution for this. I will try your method if we face any issue in future. And it would help many folks using mailgun if you could open source your C# implementation . Thank you.Juvenilia
i get 'forbidden' when i tried to call the API using cURL. why and how to get the rejected mail list? please help.Congratulation
You can now also find the permanent fail in the logs on Mailgun website and hit 'resend'. Also you can do that via the API, see example here: documentation.mailgun.com/en/latest/api-sending.html#examplesProlamine
D
0

An example from docs of how to resend a message:

curl -s --user 'api:YOUR_API_KEY' \
    https://se.api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/messages/STORAGE_URL \
    -F to='[email protected]'
Dart answered 26/10, 2020 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.