Configuring parallel mail delivery (Dual Delivery) in Postfix

This note tells how to use Postfix to organize parallel delivery of mail to several mail servers within one domain name, without the well known forwarding or mail fetching. In this case the messages for the mailbox [email protected] will be delivered to several mail servers, where that same mailbox is configured.

In the role of the secondary server I will use a business account on mail.ru. The mail server is mx.mail.ru

I had a CentOS server at my disposal with a preinstalled Postfix+Dovecot stack. The virtual mailboxes were stored in a MySQL database.

If you don’t have that luck - you can read the article: Installing and configuring Postfix

First you need to install the mail deliverer - msmtp:

yum install msmtp

If nothing was found - enable the Epel repository and repeat the previous step:

wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm  
rpm -ihv epel-release-6-8.noarch.rpm

Create a shared folder on the server:

mkdir /opt/smtpdd

Next you need to download the delivery script:

wget -O /opt/smtpdd/smtpdd.sh /wp-content/uploads/2014/05/smtpdd.sh

Create a folder for the temporary storage of the delivery queue:

mkdir /var/spool/smtpdd

Create the user the script will run as:

useradd smtpdd  
chown -R smtpdd:smtpdd /opt/smtpdd  
chown -R smtpdd:smtpdd /var/spool/smtpdd

Next open the /etc/postfix/master.cf file in your favourite editor and put this record into it:

dualdelivery unix - n n - 5 pipe  
	user=vmail argv=/opt/smtpdd/smtpdd.sh /var/spool/smtpdd ${sender} ${recipient} localhost:10026:q mx.mail.ru:25:q

Don’t forget to replace mx.mail.ru with the address of your second server.

Now create an additional filter for delivering the mail to yourself:

localhost:10026 inet n - n - - smtpd  
	-o content_filter=  
	-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks,no_milters

What is left is to enable the dualdelivery filter for the smtp service. That service is usually described in the first uncommented line of master.cf. Bring it to the following form:

smtp inet n - n - - smtpd  
	-o content_filter=dualdelivery

Now you need to make sure that one of the following parameters is declared in /etc/postfix/main.cf:

- relay_domains = yourdomain.com  
- virtual_mailbox_domains = mysql:$config_directory/virtual_domains.cf

That’s it. You can restart postfix and check that everything works.