Email_scripts
Email is great. It is a time tested standard, reliable, and federated. Today I spent some time cleaning up a couple scripts I have regarding email. Ever since I set up my own server with mailinabox.email/, I have been scripting some IMAP and SMTP things. It is much easier to do things with a custom server than with a large email provider like Gmail since you don’t have their proprietary system on top of everything. The scripts reside in this repository.
email_helper.py
This file handles all the shared code regarding IMAP and SMTP, like sending and parsing the inbox. I did not have this before today, and foolishly was just copying the send mail method in every script. In refactoring this, I accidentally sent out an email about an old post to all the subscribers on my website from the email sign up (sorry about that). I’m not quite sure how old this post was, as I don’t show years for some reason in posts, which is something I need to fix.
config.py
Manages the config file for everything. If no config file exists, it will prompt you to create one with a creation tool.
kitchen-update-email.py
This script is fairly specific, and it checks if there is a new post on my website and if so sends out the email. Most of this code is DB logic, since that’s where the information for when the last email was sent is kept. I run it in crontab, and so emails are send when my server hits midnight.
reminder.py
This is where things begin to get a bit interesting. I set up this script to send an email starting with the subject “REMINDER: " with the rest of the subject and body coming from the command arguments. This makes it really easy to set up a crontab line with the script for things like “pay rent near the end of the month” or “backup computer on the 5th”. I can see the email in my inbox when it comes, and it is a reminder to do that thing.
daily-update.py
This script does the most, and I run it every day. First, it will check my inbox for any emails that contain “REMINDER” in the subject and include their subjects in a list, just so the unread emails don’t get buried in my inbox. Next, it will go to the Library of Congress newspaper archives to find a newspaper from 100 years ago and if there is one it will appear also in the email. I find old news to be fascinating, and in the future would be interested in including some more “this day in history” features. Lastly, this script will also include a detailed weather forecast table. I have more ideas of things to include, and I am excited to extend this daily email with even more things.