Maildrop
Aller à la navigation
Aller à la recherche
Prérequis
Disposer d'un serveur mail Postfix fonctionnant avec des utilisateurs virtuels (c.f Postfix_MySQL)
Présentation
Maildrop est un MDA (Mail Delivery Agent), programme qui permet de recevoir, filtrer et délivrer les messages dans les boîtes mails des utilisateurs.
Installation
- On installe le service maildrop :
|
|
Configuration
Postfix
- On édite le fichier /etc/postfix/main.cf et on remplace :
virtual_transport = virtual
- Par :
virtual_transport = maildrop maildrop_destination_recipient_limit = 1
- Dans le fichier /etc/postfix/master.cf on remplacera :
maildrop unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/bin/maildrop -d ${recipient}
- Par :
maildrop unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/bin/maildrop -w 90 -d ${user}@${nexthop} ${extension} ${recipient} ${user} {nexthop}
Maildrop
- Il s'agit d'indiquer à Maildrop comment traiter les messages qui lui sont soumis par Postfix. Le but est ici d'indiquer où sont stocké les mails de nos utilisateurs.
- On crée le fichier de configuration /etc/maildroprc et on y ajoute la ligne suivante :
DEFAULT="/var/mail/vmail/"
- Les règles de routage des mails sont écrites dans le fichier /var/mail/vmail/.mailfilter :
USER_DIR="/var/mail/vmail/$4/$3/" to $USER_DIR
- On applique les permissions adéquates sur les fichiers utilisés par maildrop :
|
|
Configuration avancée
# Global maildrop filter file (used on Debian) # For use with Postfix/Courier IMAP/Amavisd-new virtual mailbox domains. # # This maildroprc automagically creates a Spam folder for the recipient # and places spam there. It also subscibes the recipient to the folder. # # Example maildir: /home/vmail/example.com/user/ # # Also in main.cf: # virtual_transport = maildrop # maildrop_destination_concurrency_limit = 2 # maildrop_destination_recipient_limit = 1 # # and in master.cf: # # maildrop unix - n n - - pipe # flags=DRhu user=vmail:vmail argv=/usr/bin/maildrop -w 90 -d ${user}@${nexthop} # ${extension} ${recipient} ${user} ${nexthop} # # /var/log/maildroprc.log needs to exist and owned by vmail:vmail and # a logrotate script needs to be created. # HOME_DIR="/var/mail/vmail" EXTENSION="$1" RECIPIENT=tolower("$2") USER="$3" HOST="$4" SENDER="$5" DEFAULT="$HOME_DIR/$HOST/$USER" # Check if host and user directory exist `test -e $HOME_DIR/$HOST/$USER` #log "Testing for $HOME_DIR/$HOST subdirectory: result=$RETURNCODE" # Only continue if directory does NOT exist if ($RETURNCODE != 0) { log "MailDir $HOME_DIR/$HOST/$USER does NOT exist" `test -e $HOME_DIR/$HOST` if ( $RETURNCODE != 0 ) { log "Creating $HOME_DIR/$HOST" `mkdir $HOME_DIR/$HOST` `chmod -R 0700 $HOME_DIR/$HOST` } # Create users MailDir `maildirmake $HOME_DIR/$HOST/$USER` } if (/^X-Spam-Flag: YES/) { EXTENSION = "Junk" # See if the spam directory already exists `test -e $HOME_DIR/$HOST/$USER/.$EXTENSION` #log "Testing for $EXTENSION subdirectory: result=$RETURNCODE" if ( $RETURNCODE != 0 ) # spam directory does not exist - so we create it { # Create the subdirectory `maildirmake -f $EXTENSION $HOME_DIR/$HOST/$USER` log "Ran \"maildirmake -f $EXTENSION $HOME_DIR/$HOST/$USER\"" # Auto-subscribe the subdirectory `if ! grep -q INBOX.$EXTENSION $HOME_DIR/$HOST/$USER/courierimapsubscribed; then echo INBOX.$EXTENSION >> $HOME_DIR/$HOST/$USER/courierimapsubscribed; fi` } # Deliver the message to the mailbox exception { # for those who unsubscribed themselves - subscribe them `if ! grep -q INBOX.$EXTENSION $HOME_DIR/$HOST/$USER/courierimapsubscribed; then echo INBOX.$EXTENSION >> $HOME_DIR/$HOST/$USER/courierimapsubscribed; fi` to "$HOME_DIR/$HOST/$USER/.$EXTENSION" } }