PostfixAdmin Vacation/Out of Office Autoresponder

PostfixAdmin actually comes with a perl plugin that enables a Vacation/Out of Office Autoresponder; for some reason, though, it’s not installed by default. The setup only takes a few minutes and it enables users to manage their own autoresponders, so it’s well worth the time.

This setup assumes that you’ve followed this Postfix Dovecot Mailserver Walkthrough. If not, your mileage may vary. Basically, you’ll need to have PostfixAdmin setup, and be using it to manage virtual mail users.

First, we need to grab some perl library dependancies

sudo apt-get install libmail-sender-perl libdbd-mysql-perl libemail-valid-perl libmime-perl liblog-log4perl-perl liblog-dispatch-perl libgetopt-argvfile-perl libmime-charset-perl libmime-encwords-perl

Create a user to manage the system:

sudo groupadd -r -g 65501 vacation
sudo useradd -r -u 65501 -g vacation -d /var/spool/vacation -s /sbin/nologin vacation
sudo mkdir /var/spool/vacation
cd /var/www/postfixadmin/VIRTUAL_VACATION
sudo cp vacation.pl /var/spool/vacation/vacation.pl
sudo chown -R vacation:vacation /var/spool/vacation
sudo chmod -R 700 /var/spool/vacation

Update the vacation script with your settings

sudo nano /var/spool/vacation/vacation.pl

our $db_type = ‘mysql’;
our $db_username = ‘postfix’;
our $db_password = ‘yourdbpasswd’;
our $db_name = ‘postfix’;

our $vacation_domain = ‘autoreply.yourdomain.com’;
Save and close (CTRL + X)

Update the postfixadmin config file

cd /var/www/postfixadmin
sudo nano config.inc.php

$CONF['vacation'] = ‘YES’;
$CONF['vacation_domain'] = ‘autoreply.yourdomain.com’;

cd /etc/postfix
sudo nano master.cf

Add (near the end of the file):
vacation unix – n n – - pipe flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} ${recipient}
Save and close (CTRL + X)

sudo nano main.cf

transport_maps = hash:/etc/postfix/transport
Save and close (CTRL + X)

Create (or update) a transport map to handle the redirected email

sudo nano transport

autoreply.yourdomain.com vacation
Save and close (CTRL + X)

Postfix uses a hashed file to do the lookups, the postmap command creates that file.

sudo postmap /etc/postfix/transport

Reload the postfix config to activate the changes

sudo /etc/init.d/postfix reload

That’s it. Now if you log in to your postfix admin control panel, you’ll be able to manage autoresponders for all the accounts. When users log in to their specific accounts they’ll also be able to manage their own out of office notifications.