Mailgun provides an easy way to send out emails that can be integrated in your scripts and in turn helps with automated reporting. Often times we have to run some ad-hoc reports that are short-lived (hopefully) but need to be automated so that nobody has to go through the pain of running them manually. Working with large datasets of information, this becomes a requirement for me every now and then. Most of the times it is someone requesting for information that is not exposed using a web interface or API. While making the information using a web interface or API is definitely a good long-term solution, in order to be agile, I use mailgun and a simple shell script to automate the reporting.

In this blog post, we will look at a script that will

  1. Connect to a PostgreSQL database
  2. Execute a select query
  3. Exports the information into a CSV file
  4. Email the CSV file to a list of email addresses that have been specified.

View Full Post