Photos:

China pictures processed

 
0%
 
2008.04.06 @22:18 

Postfix virtual users forwarding

Postfix virtual users forwarding

I've reinstalled completely my mail server with :

  • postfix
  • dovecot
  • ClamAV
  • ClamSMTP
  • postgrey
  • spam assassin
  • squirrelmail

Following these great articles. By the way in the first article, be sure you changed ownership of /home/vmail and everything below (domains etc...) to the vmail user or at least for him to rwx. If not your email will bounce to the recipient with the corresponding error message (something like "file or directory not found").

Everything worked as expected and quite quickly under ubuntu I must say... until I wanted to give to my users the same forwarding possibility as before (with qmail). With virtual users for some obscure security reasons (??), you cannot use the .forward (or .qmail) files !

"This agent was originally based on the Postfix local delivery agent. Modifications mainly consisted of removing code that either was not applicable or that was not safe in this context: aliases, ~user/.forward files, delivery to "|command" or to /file/name " from the postfix documentation.

Well in your /etc/postfix/vmaps you can specify redirections (john@doe.com -> johndoe@gmail.com) but you cannot save the email and forward it to one or more addresses like we often do for small mailing lists on "general" email addresses such as "contact@example.com"

As it seems it is not that easy to find a solution to this surprisingly bigger-than-I-thought small problem ! I haven't found  anything about this on internet. It's probably resolvable if you choose to store your emails in mysql (although I didnt try) but I like the old filesystem style better, easier for external scripting and it doesnt bother the database.

So I wrote a transport layer who does this. I hope it could be useful to someone.

Features :

  • no need to install an external program and should work with any postfix/imap/pop3 installation
  • deliver mails locally and/or forward to as many as addresses as you wish
  • supports aliases
  • if you use spam assassin (or another antispam which follows the same marking rules), the script can dispose automatically of your spam (delete or putting them to a server blackhole directory)

To install it :

  1. edit  /etc/postfix/main.cf and change : virtual_transport = mydrop
  2. comment your transport_maps line if any
  3. edit  /etc/postfix/master.cf and add at the end (there should be no spaces at the end of the lines)
  1. put the following script in /home/vmail/mydrop.py  and configure if needed the options at the top
  2. chmod +x /home/vmail/mydrop.py
  3. restart postfix with:  /etc/init.d/postfix restart

To use it :

By default it will deliver to the /home/vmail/domain/johndoe/ directories as before.
At any time you can create a ".qmail" file in each of the account's root (such as /home/vmail/domain/johndoe/) and as per the ususal .qmail files you can use on each line either "&johndoe@gmail.com" to forward to this email or "./Maildir/" (case insentive) to deliver locally. Example to forward to 2 addresses and keep locally :

 Let me know if you have any questions...

Note : you need to have all your domains and users to be in lowercase in your directories and your vmaps or you wont be able to receive emails in capitals.

[NOTE this has been updated on 4th of september 2008 to fix a bug] mydrop.py script :

 

"No Comments"
Post a Comment
Comments have been deactivated thanx to screwers.