Vacation
-------
Setup Vacation on Postfixadmin 3.2 Centos 7.x
I want to outline how I've solved the problem that appears on setup.
Install perl library dependancies:yum install perl-Email-Valid perl-Email-Sender perl-Email-Simple perl-Test-Email perl-Try-Tiny perl-MIME-Charset perl-MIME-EncWords perl-Log-Log4perl perl-Log-Dispatch perl-Test-mysqld -yFor Debian:apt-get installlibmail-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
2. Add user and group, crete folder. groupadd -r -g 65501 vacation useradd -r -u 65501 -g vacation -d /var/spool/vacation -s /sbin/nologin vacation
mkdir /var/spool/vacationcp /var/www/html/postfixadmin/VIRTUAL_VACATION/vacation.pl /var/spool/vacationchown -R vacation:vacation /var/spool/vacationchmod -R 750 /var/spool/vacation/vacation.pl
Setup script.vim /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’;
close file with :wq
Setup config.local.phpvim /var/www/html/postfixadmin/config.local.php
$CONF['vacation'] = ‘YES’; $CONF['vacation_domain'] = ‘autoreply.yourdomain.com’;
4. Config vacation in postfix
vim /etc/postfix/master.cf
add:vacation unix - n n - - pipe flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -- ${recipient}( do not forget to add some space in front "flags=..... " )Make sure you have this line in /etc/postfix/main.cf
transport_maps = hash:/etc/postfix/transport
vim /etc/postfix/transportautoreply.domain.org vacation:
Save file and close. After this:
postmap /etc/postfix/transportRestart Postfixsystemctl restart postfix.service.
Follow these steps if you get an error in logs like this:Aug 20 14:25:01 mail postfix/pipe[24086]: 43AF03E0B63: to=<lucian#domain.ro@autoreply.domain.ro>, orig_to=<lucian@domain.ro>, relay=vacation, delay=2, delays=1.4/0.01/0/0.56, dsn=5.3.0, status=bounced (Command died with status 255: "/var/spool/vacation/vacation.pl". Command output: Attribute (ssl) does not pass the type constraint because: Validation failed for 'Bool' with value "starttls" atconstructor Email::Sender::Transport::SMTP::new (defined at /usr/share/perl5/vendor_perl/Email/Sender/Transport/SMTP.pm line 200) line 98, <STDIN> line 38. Email::Sender::Transport::SMTP::new('Email::Sender::Transport::SMTP', 'HASH(0x433e128)') called at /var/spool/vacation/vacation.pl line 474 main::send_vacation_email('lucian@domain.ro', 'lucian@domainsender.com', 'lucian@domain.ro', '<b2f160ca41b1e4773765ad634564ff1a@domainsender.com>', 456, 0) called at /var/spool/vacation/vacation.pl line 657 )
Solution:
vim /var/spool/vacation/vacation.pl
and change
our $smtp_ssl = 'ssl'withour $smtp_ssl = '0'
----------------------------X------------------------------
postfix/Postfixadmin vacation configuration
If we want to manage vacation trough Postfixadmin we need some additional Postfix configurations. As first step we need a system user dedicated to the automatic answer management, with the lowest possible privileges; we can create it with the following commands:
groupadd -g 65501 vacationuseradd -g 65501 -u 65501 -c Vacation -s /sbin/nologin -d /nonexistent vacationthen we will need a directory for temporary files accessible only for this user, we can create it with the following commands:
mkdir /var/spool/vacationchown -R vacation.vacation /var/spool/vacationchmod o-xr /var/spool/vacationThe second step is to setup the vacation script, we need to put a copy (it's distributed with Postfixadmin) in the previous directory; this can be done with the following commands:
cd /usr/share/doc/postfixadmin/examples/VIRTUAL_VACATION/zcat vacation.pl.gz > /var/spool/vacation/vacation.plchmod 700 /var/spool/vacation/vacation.plchown vacation.vacation /var/spool/vacation/vacation.plto have the script working correctly we will also need some Perl modules; these can be installed with the command:
aptitude install libemail-valid-perl libmime-encwords-perl libmime-perl \ libmail-sender-perl liblog-log4perl-perland at last we will need to setup the script to access to the database, this can be done modifying the following lines at the beginning of it (note that we are using the same values used in the Postfixadmin configuration):
our $db_type = 'mysql';our $db_host = 'localhost';our $db_username = 'postfixadmin';our $db_password = 'secretandcomplexpassword';our $db_name = 'postfixadmin';our $vacation_domain = 'autoreply.mydomain.it';
The last step is the Postfix configuration; we will need to setup a new transport dedicates to vacation, so we need to add to /etc/postfix/master.cf the following lines:
vacation unix - n n - - pipe flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -- ${recipient}then we will need to use this transport for all mail directed to the dedicated autoreply.mydomain.it domain, so first we need to create the # vi /etc/postfix/transport file with the following line:
autoreply.mydomain.it vacation:and then add to # vi /etc/postfix/main.cf the following line:
transport_maps = hash:/etc/postfix/transportThis done we can tell Postfix to use the new configuration with the following commands:
postmap /etc/postfix/transportpostfix reload
----------X------------------------
Creating the Vacation User/Group
groupadd vacationuseradd -s/sbin/nologin -d/nonexistent -g vacation vacationSee [User Management] for more information on creating users in linux
Creating Directories
mkdir -p /var/spool/vacationcp /var/www/html/postfixadmin/VIRTUAL_VACATION/vacation.pl /var/spool/vacationchown -R vacation.vacation /var/spool/vacationchmod -R 700 /var/spool/vacationPostfix Intigration
Master.cf
Edit /etc/postfix/master.cf Add these lines at the bottom.
### Postfix Admin Vacation Messagevacation unix - n n - - pipe flags=Rhu user=vacation argv=/var/spool/vacation/vacation.pl##( do not forget to add some space in front "flags=..... " )
Transport Map
Create a transport map
touch /etc/postfix/transport_maps.cfEdit transport_maps.cf and add these lines to it. Substitute your information where needed.
user = postfixpassword = ********hosts = localhostdbname = mailquery = SELECT transport FROM transport_table WHERE domain='%s'Edit main.cf and add/change:
transport_maps = mysql:/etc/postfix/transport_maps.cfMySQL
Down and Dirty
Create a table called 'transport' Create 'domain' field varchar(255) and PKEY Create 'transport' field varchr(255)
Add your FQDN in the 'domain' field and 'virtual:' in the 'transport' field.
Add 'autoreply.yourdomain.com in the 'domain' field and 'vacation' in the 'transport' field.
it should look something like this:
+----------------------+----------+| domain | transport|+----------------------+----------+| domain.tld | virtual: || autoreply.domain.tld | vacation |+----------------------+----------+Overview
Postfix receives mail. It checks the transport_map for the appropriate transport for the recipients domain. What happens next is that the recipient has 2 aliases one to their mailbox and another to an autoreply.domain. The transport for the autoreply.domain is 'vacation' (located in master.cf) which pipes the message to vacation.pl which looks up a table in MySQL. This table contains a users vacation message. Vacation.pl then sends an email containing the recipients vacation message to the sender. Vacation.pl will only autoreply to each sender once. The sender list is cached in MySQL.
To enable a vacation message, 2 pieces of information need to be set in MySQL.
1) Append user@autoreply.domain.tld to the 'goto' field in the alias table. The goto field is a comma seperated list of aliases.
Your alias table should look something like this:
+-----------------+-------------------------------------------+------------+---------------------+---------------------+--------+| address | goto | domain | created | modified | active |+-----------------+-------------------------------------------+------------+---------------------+---------------------+--------+| user@domain.tld | user@domain.tld,user@autoreply.domain.tld | domain.tld | 2005-11-09 13:45:00 | 2005-11-09 13:45:00 | 1 |+-----------------+-------------------------------------------+------------+---------------------+---------------------+--------+2) Edit the vacation table, addind all relevant information. Do not add anything to the 'cache' field unless you do not want a vacation message sent to that user.
Your vacation table should look something like this:
+-----------------+---------------------+------------------------------------+-------+------------+---------------------+--------+| email | subject | body | cache | domain | created | active |+-----------------+---------------------+------------------------------------+-------+------------+---------------------+--------+| user@domain.tld | User is on vacation | I will be on vacation from Jan 1-7 | | domain.tld | 2005-11-09 13:45:00 | 1 |+-----------------+---------------------+------------------------------------+-------+------------+---------------------+--------+
---------------------
-----