If you’ve read the article about my email server setup you quickly realize that adding a new email account is quite onerous, a combination of adding records to tables in a MySQL database and creating folders on the harddrive. This can easily be automated with for instance PHP and I’ll show you how below.

This one will add a new email address to the database and /var/spool/vmail. Note that we’re doing the directory checks and creating non-existent directories independently of what already exists in the database or not.

This is due to the fact that you might already have information in the database that is not reflected in the vmail folder so it can’t hurt to try and create the folders anyway.

Finally the add alias script which should not be used if you alias to a domain not hosted on the server in question. Proper usage is to for instance alias from firstname@domain.com to firstname.lastname@domain.com when domain is hosted on the server in question.