< Back to Projects

Mailipy

CLI tool to send bulk-emails to a list of contacts

When organizing programming competitions, it happens quite often that I need to send an email to a fixed list of, say, a few hundred contacts: we might want to send the access credentials to each participant, or even simply communicate the starting time of the contest.

Traditionally, the method we used was to have a big Python script which parsed a CSV file and formatted some hardcoded string with all the necessary information and finally sent that string over email. This method had two big issues:

  • It's hard and repetitive: to send a new email we needed to modify the hardcoded data in the Python script.
  • It's error-prone: at some point, we had at least 3 variations of the same script with slight differences. Good luck picking the correct one!

So, one day, I set out to make our life easier and wrote Mailipy.

Installation

sudo pip install mailipy

Generating emails

The first step is to write a template, using the “Markdown + YAML front matter” syntax. It should look like this:

---
from:     "My Name <mail@example.com>"
to:       "{{Email}}"
subject:  "Some very interesting subject"
attach:   ["Rules.pdf"]
---

Hi {{Name}},

Welcome to the Contest! You will find a PDF with the rules attached to this email.

Here are the credentials you need to login in the contest:

- Username: {{Username}}
- Password: {{Password}}

Regards,  
The Staff.

Then we can generate the emails, assuming we already have our contacts.csv file:

$ mailipy-gen template.md contacts.csv

The emails are only generated, but not sent yet! This can be very useful, because it gives us a chance to inspect the email files (with .eml extension) for errors. No more sending test emails to ourselves ✨

Sending the email

Once we confirm the outbox folder looks good, we can bulk-send all emails with:

$ mailipy-send mail.example.com:528 my_username outbox/

This tool has definitely improved our workflow. Check it out on Github!

About

I’m a Software Engineer, in my free time I like cooking 🍕 playing piano 🎹 and creating programming challenges 👨‍💻I’m currently living in Zurich 🇨🇭