How To: Create E-mail Aliases on-the-fly

Overview:

Hosting your own email server can have its benefits. You not only have control over your email, but configuring dovecot/postfix is a marketable skill.

Lets say you are out on the town and stop into your local big box store. You are in the checkout line when the cashier asks if you would like to be emailed a receipt. You panic, not wanting to give out your actual email to minimize spam. If only you had a way to create email aliases on the fly when you are far away from root access to your email server. Besides setting up good spam and antivirus filtering, creating email aliases for unscrupulous websites can also be used to minimize spam.

Setup:

I will focus this on creating email aliases using an app called “t”. It directly interacts with twitter, which we will be using to add the email aliases. First, install t and create a new twitter user. You will also need to configure t for initial use  and set up a twitter api for your newly-created user. This will allow command line access to this twitter account. Detailed instructions can be found here on installing and configuring t.

The idea behind this is to tweet a direct message to your new, secondary twitter account. A cron will run a script to check for any new messages every few minutes. Content from these messages will be added as an email alias. Below is a quick and dirty script to accomplish this. A few variables need to be provided, highlighted in bold. Its best to create a new mysql user as I have, that has limited access. SELECT and INSERT are needed on mailserver.virtual_aliases if your database name is mailserver and virtual aliases table is called virtual_aliases.

This script will grab any new tweets, check the message content in the virtual_aliases table to determine if they already exist. If it does, the message is deleted. This script will loop through if there are more than one message sent per cycle.

Save this somewhere and make it executable. Add the script to cron to run every, say 10 minutes.

Try It!

From your main twitter account, send yourself a direct message to your “server” account. Wait for the next cron to run, then check your email aliases. Any questions or improvements, let me know in the comments below. Happy coding.

Leave a Reply

Your email address will not be published. Required fields are marked *