So my friend called me yesterday. He asked me to set up a mailing list service for his domain I manage.
"One thing though: I only want specific people to be able to send e-mail to the list."
Could I have found a system that has a nice GUI and does this and more? Sure. The real question is: was I going to? Absolutely not.
In this article I will tell you how to point an e-mail address to a script.
We will deal with all the python stuff later.
An e-mail address that forwards all incoming mail to a script that can process the message.
Make sure you have a domain name pointed at your server (eg: example.com), otherwise you won't be able to receive mail.
sudo apt-get install postfix sudo service postfix start
Open postfix's main configuration file with:
Make sure you have the following lines:
virtual_alias_maps = hash:/etc/postfix/virtual alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases.db
Set up aliases
We are going to use aliases to forward the incoming e-mail to our script.
With aliases messages sent to a non-existent UNIX user will be forwarded to a destination we specify (another user or in this case a script)
Open the aliases file with
sudo nano /etc/aliases
On the last line type:
scriptis the alias name you want to use (it can be anything). Make sure to type a valid path, we will put the actual script there later.
Set up virtual alias maps
Virtual alias maps will let you specify incoming e-mail addresses and what you want to do with them.
To create your virtual alias file issue:
sudo touch /etc/postfix/virtual
Then open it for editing:
sudo nano /etc/postfix/virtual
In the file enter an e-mail address and forward it to the alias we created in step 3.
Load all the stuff in postfix
To let postfix know we changed a bunch of stuff issue these commands one-by-one:
sudo postmap /etc/postfix/virtual sudo newaliases sudo postalias /etc/aliases sudo postfix reload
Postfix is now ready to forward e-mail to your script.
In the second part of this article I will show you how to process the email using python.
I have a tiny newsletter you could subscribe to.
I am also on twitter, see you there.