Procmail Configuration with Postfix


Procmail is a Mail Delivery Agent (MDA) which can sort out incoming/outgoing email. It can differentiate emails based on the keyword, from/to address etc. and deliver the email to respective inbox or discard it based on the policy. It is a very useful MDA for sorting out emails.

Step 1: Create three users e.g. allmail, incoming and outgoing.

allmail =  It contains all incoming and outgoing emails.
incoming = It contains only inbound emails from outside domain.
outgoing = It contains the outbound emails send from the self-domain to any recipient domain.

root@mail:~# adduser allmail
root@mail:~# adduser incoming
root@mail:~# adduser outgoing

Step 2: Install procmail.

root@mail: apt install procmail

Step 3: Create a file .forward to forward all emails to procmail.

root@mail:/home/allmail#vim .forward
|/usr/bin/procmail

Step 4: Create another file .procmailrc to forward inbound and outbound emails to respective email accounts.

root@mail:/home/allmail#vim .procmailrc
SHELL=/bin/sh
MAILDIR=/var/spool/mail
LOGFILE=/var/log/procmail.log
#outgoing=/var/spool/mail/outgoing
#incoming=/var/spool/mail/incoming

:0                              # Anything from people domain.com
* ^From.*@domain.com
#$outgoing
! outgoing

:0                              # Anything from people Outside domain.com
#$incoming
! incoming

Step 5: Provide necessary permissions.

root@mail:/home/allmail# chown allmail:allmail .procmailrc
root@mail:/home/allmail# chown allmail:allmail .forward

Step 6: Add a line in main.cf file to forward all emails to allmail.

root@mail: vim /etc/postfix/main.cf
always_bcc = allmail@domain.com

Step 7: Restart the postfix service.

root@mail:/etc/init.d/postfix restart

Now, check the forwarding rules by sending/receiving emails. It should work well.

Comments

Popular posts from this blog

Install a Comodo/Sectigo Domain Validation SSL certificate in Zimbra

Adding DKIM record (1024 bit) in Zimbra

Recipient Limit of a Message in Zimbra