Qmail Wildcard Aliases

Go Back
Braindump Index
Braindump Home

I had a client ask for a number of email accounts @clientdomain.com and for any email addresses that didn't match to go into a default mailbox sales@clientdomain.com

I soon realized that qmail was not capable of doing this. By using a ~alias/.qmail-default file I could deliver ALL "leftover" email to a specific mailbox - but there wasn't a way to deliver it only on a per-domain basis.

qmail only supports using locals or virtualdomains, but not a combination of both - which I would need. (The alternative was to set up ~alias/.qmail-clientdomain-user aliases for each user - and have to manage that mess too, delivering mail to mailboxes at another domain... ugly).

Instead I use the ~alias/.qmail-default file to send all non-matching email to procmail, where I filter out email for a specific domain to be forwarded - and set the rest of the mail to bounce back to the sender with a genuine qmail failure message.

  1. Create your procmail recipe file. I named this file ~alias/wildcard.procmailrc
    PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
    LOGFILE=/tmp/wildcard.procmaillog
    SHELL=/bin/sh
    
    # If a message has reached this far - qmail does not recognize the recipient, it's up
    # to us to handle the message ourselves.
    
    # qmail takes the value of the smtp 'rcpt to:' field and provides it in the message
    # headers as the Delivered-To: field.  I use that to figure out who the intended
    # recipient of the message is.
    
    :0
    *	^Delivered-To.*@clientdomain.com
    	! sales@clientdomain.com
     
    :0
    {
    	# EXITCODE returns the status code (100) to qmail, which qmail interprets as a
    	# fatal error and bounces the message for us!
    	EXITCODE=100
     
    	# procmail is still holding onto a copy of the message - and will deliver it to
    	# /var/spool/mail/alias unless we tell it to drop it.
    	:0
    	/dev/null
    }
    
  2. Next set up the ~alias/.qmail-default file that handles all uncrecognized recipients
    | /var/qmail/bin/preline /usr/bin/procmail -m wildcard.procmailrc


Last modified: Wednesday, December 31 1969 @ 19:00 EST
Google
WWW braindump.MrZesty.net
© Ian Samuel, 2012
http://braindump.MrZesty.net