< Back to Projects


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

When helping out in 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 communicate the starting time of the contest, or even simply send the access credentials to each participant.

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

  • It's hard and repetitive: to send a new email we need to modify the hardcoded string in the Python script.
  • It's error-prone: at some point, we had a folder with at least 3 variations of the same script.

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


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}}

The Staff.

At this point 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!


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

Where to find me