0

my application sends a batch of custom emails every day using mailgun (an email API service). I have a producer worker scheduled to run daily, and all does is query the database for the unique configurations/templates, and adds the jobs to redis. Then my consumer worker sends the requests to mailgun and acks them. It works well, but what's missing is statistics application-side. I want to show how many emails were sent, how many failed, etc. Where should I pull that data from?

I can imagine having the consumer put the status into the application's database before acking the message, or perhaps using mailgun's API for the stats..? Or is it common to somehow get stats from redis?

Thanks for your time

  • 1
    If mailgun is responsible for sending your emails in the first place, it would make sense to get your statistics from them. They would have the most reliable records of success / failure etc. – richzilla Feb 28 '18 at 11:54
1

To answer "Where should I store statistics about sent emails?" you should store this in a way that is easy for you to use. if you want to integrate it into your application, a database might be a good choice. If you want to just keep it for logging, file logs might be a choice.

When it comes to the question on how many failed, it depends on what you define as failed. If you just simply defines failed as "invalid mailbox" you can send with a special and valid email address. You will (at least normally) get an email back with information about the email address and a status on why it failed. You can then read this mailbox (either automatically or manually) and count how many failed emails (and delete them after counting is done)

You will have to log all email sendt into the database and based on how many "invalid mailbox" emails you get, you know how many where successfully delivered.

But this will not give you any clue about how many ended up in a spam folder. To get some idea about it, you can put an image into the email and pointing the src of the image to a unique url on your server (http://myserver.com/image/uniqueid.jpg) and have some server side code registrering the request. In this way you can track when the email has been opened. However this will not work for email client thats blocks automatically downloading of external data (like outlook)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.