How to improve email robustness? [mailgun, laravel]

Viewed 286

I planned to improve email robustness using below way. I am using laravel and mailgun. If any bounces email is in the mailgun then i want to send that to someone related to the email(not to that previous receiver and it related with previous sender or someone) so that i plan to use Task scheduler and schedule every hour this process. After that email send successfully i want to remove that email from mailgun.

I actually want to know how to implement get bounces email from mailgun and if send successfully using Task scheduler i want to remove that email from mailgun. if any sample's to achieve this? or any different ideas?

1 Answers

Normally when a bounce happens, providers such as Mailgun will retry a few times depending on the bounce status/type. After failing to send to that email address, Mailgun will put that address into your Bounces list to avoid sending to that address in the future. There's really no point in trying to send emails to an address which doesn't exist, inbox is full, domain expired, etc. So perhaps you should review your bounce list before you consider doing this. Mailgun's dashboard provides the description and date it happened. If you wish to send to a particular address again, you can remove the address from the bounce list. More about bounces here.

You can use mailgun-php or simply use Guzzle to call their API to retrieve your bounces. I'm not sure what you meant my removing email, but hope this helps.

Edit:

You can use their API to get all your bounces, and also the message content (retention depends on your plan or settings) if you need the original content. You could also use their webhooks to get the failed emails, so you don't really need to schedule/cron.

Edit 2:

The bounce list only stores email addresses of previously bounced emails. Also, I just realized that, if you're checking hourly for bounced messages, looks like the suppression/bounce API won't be of much help since you can't know if a message has failed for an address already on the list. This is the only data from bounce list:

      {
        "address": "alice@example.com",
        "code": "550",
        "error": "No such mailbox",
        "created_at": "Fri, 21 Oct 2011 11:02:55 GMT"
      },

So looks like you've to use the events API or webhooks to get the failed messages. I've used mailgun-php sometime ago, and I found that the it wasn't easy working with Events on that library due to protected properties of the class. So if you have trouble, maybe just use Guzzle or use webhook approach instead.

Related