Saturday, January 23, 2010

Postfix Vacation Autoresponder

SkyHi @ Saturday, January 23, 2010

This article describes how to configure a vacation autoresponder in Postfix mail server so email senders can be informed when the recipient is not available.

Installing the Vacation Perl Script

Postfix Admin Main
1. Install Postfix Admin. We are not going to actually use Postfix Admin, we are just going to leverage its excellent vacation message infrastructure. You can skip this part if you are actually using Postfix Admin to manage your Postfix mail server.
Install RPMforge
2. Add the RPMforge repository. The RPMforge repository is needed to install the required modules for the vacation.pl script.
yum install
3. Type in the command below to install the required Perl modules.
yum install perl-MIME-EncWords perl-MIME-Charset
perl-Email-Valid perl-Mail-Sendmail
Create user vacation
4. Create a new user named vacation. Change the Login Shell to /sbin/nologin, this user account should not be used for logging in. Learn how to use the User Manager application here.
Copy vacation.pl
5. Type in the commands below to copy vacation.pl to the vacation user home directory.
cd /home/vacation
wget www.linuxmail.info/files/vacation.pl
chown vacation:vacation vacation.pl
chmod 700 vacation.pl
vacation.pl
6. Type in the command below to test vacation.pl. No error should appear.
./vacation.pl

Configuring Postfix

Edit transport
1. Edit the file /etc/postfix/transport and add the line below.
vacation.invalid vacation:
Next, type in the command below to convert it to a database file.
postmap /etc/postfix/transport
Edit master.cf
2. Edit the file /etc/postfix/master.cf and add the line below.
vacation unix - n n - - pipe flags=Rq user=vacation
argv=/home/vacation/vacation.pl ${recipient} ${original_recipient}
Note${original_recipient} requires at least Postfix 2.5 but you can remove it if you prefer not to upgrade. It enables vacation.pl to work with aliases like in the example below.
Email
(original recipient)
Forwards to
(recipient)
john@acme.localjohndoe@acme.local
jane@acme.localjanedoe@acme.local
Edit mysql-aliases.cf
3. Create the file /etc/postfix/mysql-aliases.cf containing the lines below.
host = localhost
user = postfix
password = your_password
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'

user, password, dbname should match your PostfixAdmin settings.

Edit transport
4. Edit the file /etc/postfix/main.cf and add the lines below.
virtual_alias_maps = mysql:/etc/postfix/mysql-aliases.cf
transport_maps = hash:/etc/postfix/transport
NoteIf you already have an existing virtual_alias_maps, add the mysql-aliases into the end like the one below.
virtual_alias_maps = ldap:/etc/postfix/ldap-groups.cf,
mysql:/etc/postfix/mysql-aliases.cf
NoteIf adding the vacation domain conflicts with your existing virtual_alias_maps, use recipient_bcc_maps instead and replace /etc/postfix/mysql-aliases.cf with the lines below.
host = localhost
user = postfix
password = your_password
dbname = postfix
table = vacation
select_field = email
where_field = email
additional_conditions = and active = '1'
result_format = %u@vacation.invalid
Service Configuration
5. Restart the Postfix or MailScanner service if you have installed it. Learn how to start and stop services here.
SquirrelMail Test Vacation
6. Send an email to test@vacation.invalid. You should get an automated reply.

Configuring the Vacation Perl Script

Edit vacation.conf
1. Create the file /home/vacation/vacation.conf containing the lines below.
$db_username = 'postfix';
$db_password = 'secret';
$db_name = 'postfix';
$test_mode = 0;
1;

$db_username, $db_password, $db_name should match your PostfixAdmin settings.

SquirrelMail Auto Response
2. Install the SquirrelMail Postfix Admin Plugin and set a vacation message and to a user.
postmap vacation
3. Verify your vacation setting by typing the command below.
postmap -q johndoe@acme.local mysql:/etc/postfix/mysql-aliases.cf
Replace johndoe@acme.local with the email address where you have configured a vacation message. The output should contain an email address for the vacation.invalid domain.
SquirrelMail Auto Response
4. Send an email to the user with a vacation message. You should receive an automatic reply.