7.2. Vacation

Vacation script that we will be using requires some Perl modules:

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

Create user vacation on your system. This user will handle the vacation script and should have minimal privileges:

adduser vacation --no-create-home --disabled-login
mkdir /var/spool/vacation

Copy the vacation.pl script (it is distributed with Postfix Admin) and you can find it inside the VIRTUAL_VACATION folder.

cp /var/www/postfix/VIRTUAL_VACATION/vacation.pl /var/spool/vacation/vacation.pl
chown -R vacation:vacation /var/spool/vacation/
chmod 700 /var/spool/vacation/vacation.pl

Create a file called /etc/postfix/transport.

autoreply.example.com        vacation:

Replace example.com with your own domain.

This is the domain that will be used for passing the mail to the vacation script. When vacation is activated an alias is created that forwards mail that is delivered to username@example.com to username@autoreply.example.com. The vacation scripts gets that email and decides how to respond.

Edit /etc/hosts and add

your-ip-address   autoreply.example.com autoreply

Create a hash of the transport map:

postmap /etc/postfix/transport

Edit /etc/postfix/main.cf and add

transport_maps = hash:/etc/postfix/transport

Add vacation transport to the /etc/postfix/master.cf.

vacation    unix  -       n       n       -       -       pipe
  flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -- ${recipient}

You also have to edit the amavis transport to add no_address_mappings in the receive_override_options so your transport for amavis should now look like this:

127.0.0.1:10025 inet    n       -       -       -       -       smtpd
      -o content_filter=
      -o local_recipient_maps=
      -o relay_recipient_maps=
      -o smtpd_restriction_classes=
      -o smtpd_delay_reject=no
      -o smtpd_client_restrictions=permit_mynetworks,reject
      -o smtpd_helo_restrictions=
      -o smtpd_sender_restrictions=
      -o smtpd_recipient_restrictions=permit_mynetworks,reject
      -o smtpd_data_restrictions=reject_unauth_pipelining
      -o smtpd_end_of_data_restrictions=
      -o mynetworks=127.0.0.0/8
      -o smtpd_error_sleep_time=0
      -o smtpd_soft_error_limit=1001
      -o smtpd_hard_error_limit=1000
      -o smtpd_client_connection_count_limit=0
      -o smtpd_client_connection_rate_limit=0
      -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_address_mappings

Edit /var/spool/vacation/vacation.pl and change the configuration settings to match your system (set database type, database settings, vacation domain, etc.)

Reload Postfix and commit your changes.

/etc/init.d/postfix restart
etckeeper commit "Added vacation"

To handle the Vacation using Postfix admin you will also have to edit its config.inc.php file and set

$CONF['vacation'] = 'YES';
$CONF['vacation_domain'] = 'autoreply.example.com';

You can use Postfix Admin tu toggle vacations and change the vacation message.