Aller au contenu | Aller au menu | Aller à la recherche


Debian Squeeze : Postfix VDA + MySQL + SASL + PostfixAdmin + Courier + Virtual Users Domains + Serveur de mail SMTP IMAP POP3 + Webmail

Comment configurer simplement sur serveur de mail multi-domaines avec les droits délégués pour chaque (sous) administrateur ? ce que Zimbra n'inclut pas dans sa version gratuite.

Voici comment installer les logiciels mails serveurs et clients web sur une Debian Squeeze configurée avec :

  1. MySQL pour gérer les utilisateurs virtuels
  2. Postfix (2.7.1) + le patch quota Posftix VDA
  3. SASL SMTP
  4. le MTA Courrier IMAP et POP (alternativement nous aurions plus utiliser Dovecot)
  5. PostfixAdmin (2.3.4) l'administration des domaines, des utilisateurs et des quotas
  6. Clients webmail
    1. Roundcube webmail (0.6) (avec la visualisation du quota utilisé)
    2. Squirrelmail (1.4.22) (avec la visualisation du quota utilisé)

Je ne vais reprendre l'installation complète, car de nombreux tuto français ou anglais expliquent cela (chacun à sa manière et avec ses différences), mais voici quelques notes.

Notes

Postfix et quota

Par défaut Postfix n'inclus pas les quotas des utilisateurs, ils faut le patcher avec Posftix VDA, puis l'installer et le configurer (Available options and examples).

Description des fonctionnalités de "Posftix VDA" :

  • Brings per mailbox/maildir quota support to Postfix VDA
  • Support for Courier style maildir format, including maildirsize file
  • Limit either only INBOX or whole maildir
  • Customizable bounce message, used if mails are bounced (it's also an option)
  • Customisable suffix for Maildir support, sometimes needed for Courier IMAP
  • Enhanced patch delivery abilities using vfilter

Paquets installés au final

# cat /etc/debian_version
6.0.6

# dpkg -l | grep courier
ii  courier-authdaemon                  0.63.0-3                     Courier authentication daemon
ii  courier-authlib                     0.63.0-3                     Courier authentication library
ii  courier-authlib-mysql               0.63.0-3                     MySQL support for the Courier authentication library
ii  courier-authlib-userdb              0.63.0-3                     userdb support for the Courier authentication library
ii  courier-base                        0.65.0-3                     Courier mail server - base system
ii  courier-imap                        4.8.0-3                      Courier mail server - IMAP server
ii  courier-pop                         0.65.0-3                     Courier mail server - POP3 server

# dpkg -l | grep postfix
ii  postfix                             2.7.1-1+squeeze1             High-performance mail transport agent
ii  postfix-doc                         2.7.1-1+squeeze1             Documentation for Postfix
ii  postfix-mysql                       2.7.1-1+squeeze1             MySQL map support for Postfix
ii  postfixadmin                        2.3rc7                       Virtual mail hosting interface for Postfix

# dpkg -l | grep mysql
ii  courier-authlib-mysql               0.63.0-3                     MySQL support for the Courier authentication library
ii  libdbd-mysql-perl                   4.016-1                      Perl5 database interface to the MySQL database
ii  libmysqlclient16                    5.1.63-0+squeeze1            MySQL database client library
ii  mysql-client-5.5                    5.5.25a-1~dotdeb.1           MySQL database client binaries
ii  mysql-client-core-5.5               5.5.25a-1~dotdeb.1           MySQL database core client binaries
ii  mysql-common                        5.5.25a-1~dotdeb.1           MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server-5.5                    5.5.25a-1~dotdeb.1           MySQL database server binaries and system database setup
ii  mysql-server-core-5.5               5.5.25a-1~dotdeb.1           MySQL database server binaries
ii  php5-mysql                          5.3.14-1~dotdeb.0            MySQL module for php5
ii  postfix-mysql                       2.7.1-1+squeeze1             MySQL map support for Postfix
ii  pure-ftpd-mysql                     1.0.28-3+squeeze1            Secure and efficient FTP server with MySQL user authentication

# dpkg -l | grep sasl
ii  libsasl2-2                          2.1.23.dfsg1-7               Cyrus SASL - authentication abstraction library
ii  libsasl2-modules                    2.1.23.dfsg1-7               Cyrus SASL - pluggable authentication modules
ii  sasl2-bin                           2.1.23.dfsg1-7               Cyrus SASL - administration programs for SASL users database

# dpkg -l | grep fam
rc  fam                                 2.7.0-17                     File Alteration Monitor
rc  libfam0                             2.7.0-17                     Client library to control the FAM daemon

# dpkg -l | grep gamin
ii  gamin                               0.1.10-2+b1                  File and directory monitoring system
ii  libgamin0                           0.1.10-2+b1                  Client library for the gamin file and directory monitoring system

Commandes utiles

authtest

La commande authtest permet de contrôler le fonctionnement de l'authentification dans courier (soit imap et pop)

# authtest seb@mondomaine.fr
Authentication succeeded.

     Authenticated: seb@mondomaine.fr  (uid 1001, gid 1001)
    Home Directory: /var/mail/virtual/
           Maildir: mondomaine.fr/seb@mondomaine.fr/
             Quota: 2097152
Encrypted Password: $1$190b4d59$TocWPHqN/iCLdVI8y9BML.
Cleartext Password: (none)
           Options: (none)

Vous pouvez également vérifier si le mot de passe fonctionne :

# authtest seb@mondomaine.fr lebonmotdepasse
Authentication succeeded.

     Authenticated: seb@mondomaine.fr  (uid 1001, gid 1001)
    Home Directory: /var/mail/virtual/
           Maildir: mondomaine.fr/seb@mondomaine.fr/
             Quota: 2097152
Encrypted Password: $1$872732db$UvVCuOGS/ra2O5vC2/i85/
Cleartext Password: lebonmotdepasse
           Options: (none)

# authtest seb@mondomaine.fr lemauvaismotdepasse
Authentication FAILED: Operation not permitted
Gestion de la liste de mails

Lister les messages en queue :

postqueue -p

Effacer 1 message en queue :

postsuper -d DBB3F1A7

Pour vider les mails en queue :

postsuper -d ALL

Lire un message :

postcat -q DBA3F1A9

Forcer l’envoie des messages en queue :

postqueue -f

Tutoriels

# Création du groupe et compte "vmail"
addgroup --gid 1001 vmail
adduser --no-create-home --uid 1001 --gid 1001 vmail

Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Debian Squeeze)

Install Postfix, Courier, Saslauthd, MySQL, phpMyAdmin
apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql libpam-smbpass
Apply The Quota Patch To Postfix
# We have to get the Postfix sources, patch it with the quota patch, build new Postfix .deb packages and install those .deb packages:
apt-get build-dep postfix
cd /usr/src
apt-get source postfix
 
postconf -d | grep mail_version
# vérifiez la version (mail_version = 2.7.1)
 
# Patchin Postfix with VDA patch
wget http://vda.sourceforge.net/VDA/postfix-vda-2.7.1.patch
cd postfix-2.7.1
patch -p1 < ../postfix-vda-2.7.1.patch
dpkg-buildpackage
 
# Now we go one directory up, that's where the new .deb packages have been created:
cd ..
# Pick the postfix and postfix-mysql packages and install them like this: 
dpkg -i postfix_2.7.1-1_amd64.deb postfix-mysql_2.7.1-1_amd64.deb
Create The MySQL Database For Postfix/Courier

Utilisation de la configuration de PosftixAdmin

INSTALL.TXT

REQUIRED!!
----------
- You are using Postfix 2.0 or higher.
- You are using Apache 1.3.27 / Lighttpd 1.3.15 or higher.
- You are using PHP 5.1.2 or higher.
- You are using MySQL 3.23 or higher (5.x recommended) OR PostgreSQL 7.4 (or higher)


READ THIS FIRST!
----------------
When this is an upgrade from Postfix Admin 1.5.4 please read DOCUMENTS/UPGRADE.TXT!!

If you need to setup Postfix to be able to handle Virtual Domains and Virtual
Users check out :
2. Setup a Database
-------------------

With your chosen/preferred database server (i.e. MySQL or PostgreSQL),
you need to create a new database. A good name for this could be :

  postfix

The mechanics of creating the database vary depending on which server
you are using. Most users will find using phpMyAdmin or phpPgAdmin the
easiest route.

If you wish to use the command line, you'll need to do something like :

For MySQL:
  CREATE DATABASE postfix;
  CREATE USER 'postfix'@'localhost' IDENTIFIED BY 'choose_a_password';
  GRANT ALL PRIVILEGES ON `postfix` . * TO 'postfix'@'localhost';


4. Check settings, and create Admin user
----------------------------------------

Hit http://yourserver.tld/postfixadmin/setup.php in a web browser.

You should see a list of 'OK' messages.

The setup.php script will attempt to create the database structure
(or upgrade it if you're coming from a previous version).

Vous devriez avoir tes tables suivantes :

-- 
-- Structure générée avec postfixadmin 2.3.4
-- 
-- Base de données: `postfix`
-- 
-- --------------------------------------------------------
-- 
-- Structure de la table `admin`
-- 
 
CREATE TABLE IF NOT EXISTS `admin` (
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Admins';
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `alias`
-- 
 
CREATE TABLE IF NOT EXISTS `alias` (
  `address` varchar(255) NOT NULL,
  `goto` text NOT NULL,
  `domain` varchar(255) NOT NULL,
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`address`),
  KEY `domain` (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Aliases';
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `alias_domain`
-- 
 
CREATE TABLE IF NOT EXISTS `alias_domain` (
  `alias_domain` varchar(255) NOT NULL,
  `target_domain` varchar(255) NOT NULL,
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`alias_domain`),
  KEY `active` (`active`),
  KEY `target_domain` (`target_domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Domain Aliases';
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `config`
-- 
 
CREATE TABLE IF NOT EXISTS `config` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) CHARACTER SET latin1 NOT NULL DEFAULT '',
  `value` varchar(20) CHARACTER SET latin1 NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci COMMENT='PostfixAdmin settings' AUTO_INCREMENT=2 ;
 
-- 
-- Contenu de la table `config`
-- 
 
INSERT INTO `config` (`id`, `name`, `value`) VALUES
(1, 'version', '740');
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `domain`
-- 
 
CREATE TABLE IF NOT EXISTS `domain` (
  `domain` varchar(255) NOT NULL,
  `description` varchar(255) CHARACTER SET utf8 NOT NULL,
  `aliases` int(10) NOT NULL DEFAULT '0',
  `mailboxes` int(10) NOT NULL DEFAULT '0',
  `maxquota` bigint(20) NOT NULL DEFAULT '0',
  `quota` bigint(20) NOT NULL DEFAULT '0',
  `transport` varchar(255) NOT NULL,
  `backupmx` tinyint(1) NOT NULL DEFAULT '0',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Domains';
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `domain_admins`
-- 
 
CREATE TABLE IF NOT EXISTS `domain_admins` (
  `username` varchar(255) NOT NULL,
  `domain` varchar(255) NOT NULL,
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Domain Admins';
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `fetchmail`
-- 
 
CREATE TABLE IF NOT EXISTS `fetchmail` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `mailbox` varchar(255) NOT NULL,
  `src_server` varchar(255) NOT NULL,
  `src_auth` enum('password','kerberos_v5','kerberos','kerberos_v4','gssapi','cram-md5','otp','ntlm','msn','ssh','any') CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
  `src_user` varchar(255) NOT NULL,
  `src_password` varchar(255) NOT NULL,
  `src_folder` varchar(255) NOT NULL,
  `poll_time` int(11) unsigned NOT NULL DEFAULT '10',
  `fetchall` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `keep` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `protocol` enum('POP3','IMAP','POP2','ETRN','AUTO') CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
  `usessl` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `extra_options` text,
  `returned_text` text,
  `mda` varchar(255) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `log`
-- 
 
CREATE TABLE IF NOT EXISTS `log` (
  `timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `username` varchar(255) NOT NULL,
  `domain` varchar(255) NOT NULL,
  `action` varchar(255) NOT NULL,
  `data` text NOT NULL,
  KEY `timestamp` (`timestamp`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Log';
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `mailbox`
-- 
 
CREATE TABLE IF NOT EXISTS `mailbox` (
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `name` varchar(255) CHARACTER SET utf8 NOT NULL,
  `maildir` varchar(255) NOT NULL,
  `quota` bigint(20) NOT NULL DEFAULT '0',
  `local_part` varchar(255) NOT NULL,
  `domain` varchar(255) NOT NULL,
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`username`),
  KEY `domain` (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Mailboxes';
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `quota`
-- 
 
CREATE TABLE IF NOT EXISTS `quota` (
  `username` varchar(255) CHARACTER SET latin1 NOT NULL,
  `path` varchar(100) CHARACTER SET latin1 NOT NULL,
  `current` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`username`,`path`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `quota2`
-- 
 
CREATE TABLE IF NOT EXISTS `quota2` (
  `username` varchar(100) CHARACTER SET latin1 NOT NULL,
  `bytes` bigint(20) NOT NULL DEFAULT '0',
  `messages` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `vacation`
-- 
 
CREATE TABLE IF NOT EXISTS `vacation` (
  `email` varchar(255) NOT NULL,
  `subject` varchar(255) CHARACTER SET utf8 NOT NULL,
  `body` text CHARACTER SET utf8 NOT NULL,
  `cache` text NOT NULL,
  `domain` varchar(255) NOT NULL,
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`email`),
  KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Vacation';
 
-- --------------------------------------------------------
 
-- 
-- Structure de la table `vacation_notification`
-- 
 
CREATE TABLE IF NOT EXISTS `vacation_notification` (
  `on_vacation` varchar(255) CHARACTER SET latin1 NOT NULL,
  `notified` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
  `notified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`on_vacation`,`notified`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Vacation Notifications';
 
-- 
-- Contraintes pour les tables exportées
-- 
 
-- 
-- Contraintes pour la table `vacation_notification`
-- 
ALTER TABLE `vacation_notification`
  ADD CONSTRAINT `vacation_notification_pkey` FOREIGN KEY (`on_vacation`) REFERENCES `vacation` (`email`) ON DELETE CASCADE;

README.Debian

PostfixAdmin for Debian
=======================

After installing the package, you should find that :

http://youserver/postfixadmin/setup.php works. This should
guide you through the appropriate process.

You will need to create a database (either MySQL or PostgreSQL)
and know the username and password for it. The Database does not need
to be on the same server as the Postfixadmin install.



Recommended and Suggested Packages
==================================

 - Postfix
 - MySQL or PostgreSQL
 - Courier or Dovecot
Quota Exceedance Notifications

Visualiser le quota mail (imap) utilisé

  1. Avec les Webmail (Roundcube, Squirrelmail, ...) en général c'est affiché si c'est configuré (avec au besoin le plugin quota).
  2. Avec les clients lourds installés sur le poste client
    1. Windows Live Mail ?.. je ne crois pas que cela soit possible... faut il la version pro ?..
    2. Thunderbird  : Add-ons : Display Quota

Alerter (l'administrateur et ou les utilisateurs) qui ont les boites mail qui saturent leur quota

quota.pl et quota_notify.pl (Author <jps@tntmax.com>)

Rajoutez ce script perl dans votre cron pour alerter l'admin des utilisateurs dont le quota dépasse un pourcentage. Et optionnellement alerter les utilisateurs que leur boite mail est bientôt pleine.

#!/usr/bin/perl -w
 
# Author <jps@tntmax.com>
#
# This script assumes that virtual_mailbox_base in defined
# in postfix's main.cf file. This directory is assumed to contain
# directories which themselves contain your virtual user's maildirs.
# For example:
#
# -----------/
#            |
#            |
#    home/vmail/domains/
#        |          |
#        |          |
#  example.com/  foo.com/
#                   |
#                   |
#           -----------------
#           |       |       |
#           |       |       |
#         user1/   user2/  user3/
#                           |
#                           |
#                        maildirsize
#
 
use strict;
 
my $POSTFIX_CF = "/etc/postfix/main.cf";
my $MAILPROG = "/usr/sbin/sendmail -t";
my $WARNPERCENT = 85;
my @POSTMASTERS = ('postmaster@placeoweb.com');
my $CONAME = 'Quota mail';
my $COADDR = 'postmaster@placeoweb.com';
my $SUADDR = 'postmaster@placeoweb.com';
my $MAIL_REPORT = 1;
my $MAIL_WARNING = 1;
 
#get virtual mailbox base from postfix config
open(PCF, "< $POSTFIX_CF") or die $!;
my $mboxBase;
while (<PCF>) {
   next unless /virtual_mailbox_base\s*=\s*(.*)\s*/;
   $mboxBase = $1;
}
close(PCF);
 
#assume one level of subdirectories for domain names
my @domains;
opendir(DIR, $mboxBase) or die $!;
while (defined(my $name = readdir(DIR))) {
   next if $name =~ /^\.\.?$/;        #skip '.' and '..'
   next unless (-d "$mboxBase/$name");
   push(@domains, $name);
}
closedir(DIR);
#iterate through domains for username/maildirsize files
my @users;
chdir($mboxBase);
foreach my $domain (@domains) {
        opendir(DIR, $domain) or die $!;
        while (defined(my $name = readdir(DIR))) {
           next if $name =~ /^\.\.?$/;        #skip '.' and '..'
           next unless (-d "$domain/$name");
#          push(@users, {"$name\@$domain" => "$mboxBase/$domain/$name"});       # Compte sans le domaine : domaine.fr/user
           push(@users, {"$name" => "$mboxBase/$domain/$name"});                # Compte avec le domaine : domaine.fr/user@domaine.fr
        }
}
closedir(DIR);
 
#get user quotas and percent used
my (%lusers, $report);
my (%qusers);
foreach my $href (@users) {
   foreach my $user (keys %$href) {
      my $quotafile = "$href->{$user}/maildirsize";
      next unless (-f $quotafile);
      open(QF, "< $quotafile") or die $!;
      my ($firstln, $quota, $used);
      while (<QF>) {
         my $line = $_;
              if (! $firstln) {
                 $firstln = 1;
                 die "Error: corrupt quotafile $quotafile"
                    unless ($line =~ /^(\d+)S/);
                 $quota = $1;
            last if (! $quota);
            next;
         }
         die "Error: corrupt quotafile $quotafile"
            unless ($line =~ /\s*(-?\d+)/);
         $used += $1;
      }
      close(QF);
      next if (! $used);
      my $percent = int($used / $quota * 100);
#printf $user;
      $lusers{$user} = $percent unless not $percent;
$qusers{$user}{"quota"} = $quota;
$qusers{$user}{"qused"} = $used;
$qusers{$user}{"quotaM"} = int($quota / 1024 / 1024);
$qusers{$user}{"qusedM"} = int($used / 1024 / 1024);
#printf @qusers;
   }
}
 
#send a report to the postmasters
if ($MAIL_REPORT) {
   open(MAIL, "| $MAILPROG");
   select(MAIL);
   map {print "To: $_\n"} @POSTMASTERS;
   print "From: $COADDR\n";
   print "Subject: Daily Quota Report.\n";
   print "DAILY QUOTA REPORT:\n\n";
   print "----------------------------------------------\n";
#   print "| % USAGE |            ACCOUNT NAME          |\n";
   print "  QUOTA  | % USAGE |            ACCOUNT NAME          |\n";
   print "----------------------------------------------\n";
   foreach my $luser ( sort { $lusers{$b} <=> $lusers{$a} } keys %lusers ) {
#printf("$luser");
#printf($lusers{"quota"});
 
#printf($qusers{$luser}{"qusedM"});
#printf("/");
#printf($qusers{$luser}{"quotaM"});
 
#printf($qusers{$luser}{"qused"});
#printf("%8dMo/%8dMo  ", $qusers{$luser}{"qusedM"}, $qusers{$luser}{"quotaM"});
#printf($qusers{$luser}{"quota"});
#      printf("|   %3d   | %32s |\n", $lusers{$luser}, $luser);
      printf("%3dMo/%3dMo |   %3d   | %32s |\n", $qusers{$luser}{"qusedM"}, $qusers{$luser}{"quotaM"}, $lusers{$luser}, $luser);
      print "---------------------------------------------\n";
   }
   print "\n--\n";
   print "$CONAME\n";
   close(MAIL);
}
 
#email a warning to people over quota
if ($MAIL_WARNING) {
        foreach my $luser (keys (%lusers)) {
           next unless $lusers{$luser} >= $WARNPERCENT;       # skip those under quota
#print STDOUT "luser:$luser\n";
#if( $luser eq "seb\@comspa.fr") {
#printf STDOUT "On envoi !\n";
 
           open(MAIL, "| $MAILPROG");
           select(MAIL);
           print "To: $luser\n";
      map {print "BCC: $_\n"} @POSTMASTERS;
           print "From: $SUADDR\n";
#           print "Subject: WARNING: Your mailbox is $lusers{$luser}% full.\n";
           print "Subject: ATTENTION: Votre boite mail est pleine à $lusers{$luser}%.\n";
           print "Reply-to: $SUADDR\n";
 
           print "Votre boite mail: $luser est pleine à $lusers{$luser}%.\n\n";
#           print "Une fois votre boîte e-mail a dépassé votre quota de stockage mensuels\n";
#           print "votre facture mensuelle sera automatiquement ajustée.\n";
           print "S'il vous plaît, supprimez des e-mail et videz vos répertoires 'corbeille' et 'envoyé' pour retrouver de l'espace.\n";
           print "Autrement, si votre boite mail venait à être pleine à 100%, vous ne receverez plus aucun mail,\n";
           print "vos expéditeurs receveront une notification d'echec : 'Undelivered Mail Returned to Sender'.\n\n";
           print "Contactez <$SUADDR> pour plus d'assistance.\n";
           print "Merci.\n\n";
 
           print "\n\n";
 
           print "WARNING:\n";
           print "Your mailbox: $luser is $lusers{$luser}% full.\n\n";
#           print "Once your e-mail box has exceeded your monthly storage quota\n";
#           print "your monthly billing will be automatically adjusted.\n";
           print "Please consider deleting e-mail and emptying your trash folder to clear some space.\n";
           print "Otherwise, if your mailbox was 100% full, you no longer receive any mail,\n";
           print "your senders receive a failure notification: 'Undelivered Mail Returned to Sender'.\n\n";
           print "Contact <$SUADDR> for further assistance.\n";
           print "Thank You.\n\n";
 
           print "--\n";
           print "$CONAME\n";
           close(MAIL);
#}
        }
}

Autres ressources

Squeeze

Lenny

Autre

Problèmes rencontrés

Courier IMAP quota problem

La commande IMAP GETQUOTAROOT "INBOX" ne retourne pas le STORAGE attendu :

A001 GETQUOTAROOT "INBOX"
* QUOTAROOT "INBOX" "ROOT"
* QUOTA "ROOT"
A001 OK GETQUOTAROOT Ok.

au lieu de

A001 GETQUOTAROOT "INBOX"
* QUOTAROOT "INBOX" "ROOT"
* QUOTA "ROOT" (STORAGE 2046 2048)
A001 OK GETQUOTAROOT Ok.

N'oubliez pas de configurer le champ quota dans /etc/courier/authmysqlrc :

##NAME: MYSQL_QUOTA_FIELD:0
#
# Define MYSQL_QUOTA_FIELD to be the name of the field that can optionally
# specify a maildir quota.  See README.maildirquota for more information
#
MYSQL_QUOTA_FIELD       quota

De relancer les services courrier concernés :

/etc/init.d/courier-authdaemon restart

/etc/init.d/courier-imap restart

Et ensuite de vous envoyer un mail, qui aura pour conséquence de mettre à jour la valeur du quota utilisé par l'utilisateur dans le fichier "maildirsize" :

# cat /var/mail/virtual/mondomaine.fr/seb@mondomaine.fr/maildirsize
2097152S
     2076371           25
4608 1
6038 1
7537 1
Modification du quota de l'utilisateur alors que son fichier maildirsize indique un quota plein

Pour gérer le problème de maildirsize, le plus simple est de supprimer le fichier maildirsize (qui sera recréé lors de la prochaine réception de mail) de(s) l'utilisateur(s).

/var/mail/virtual# rm */*/maildirsize
Debuguer IMAP et les connexions MySQL
# vim /etc/courier/authdaemonrc

##NAME: DEBUG_LOGIN:0
#
# Dump additional diagnostics to syslog
#
# DEBUG_LOGIN=0   - turn off debugging
# DEBUG_LOGIN=1   - turn on debugging
# DEBUG_LOGIN=2   - turn on debugging + log passwords too
#
# ** YES ** - DEBUG_LOGIN=2 places passwords into syslog.
#
# Note that most information is sent to syslog at level 'debug', so
# you may need to modify your /etc/syslog.conf to be able to see it.

DEBUG_LOGIN=2


Ce qui vous donnera des logs tels que /var/log/syslog
Dec 11 17:12:50 sd-13047 imapd: LOGIN, user=seb@mondomaine.fr, ip=[::ffff:82.242.241.128], port=[55546], protocol=IMAP
Dec 11 17:12:50 sd-13047 imapd: DISCONNECTED, user=seb@mondomaine.fr, ip=[::ffff:82.242.241.128], headers=0, body=0, rcvd=275, sent=536, time=0
Dec 11 17:12:50 sd-13047 imapd: Connection, ip=[::ffff:82.242.241.128]
Dec 11 17:12:50 sd-13047 authdaemond: received auth request, service=imap, authtype=login
Dec 11 17:12:50 sd-13047 authdaemond: authmysql: trying this module
Dec 11 17:12:50 sd-13047 authdaemond: SQL query: SELECT username, password, "", '1001', '1001', '/var/mail/virtual/', maildir, quota, name, "" FROM mailbox WHERE username = 'seb@mondomaine.fr'
Dec 11 17:12:50 sd-13047 authdaemond: password matches successfully
Dec 11 17:12:50 sd-13047 authdaemond: authmysql: sysusername=, sysuserid=1001, sysgroupid=1001, homedir=/var/mail/virtual/, address=seb@mondomaine.fr, fullname=, maildir=mondomaine.fr/seb@mondomaine.fr/, quota=2097152, options=
Dec 11 17:12:50 sd-13047 authdaemond: authmysql: clearpasswd=, passwd=$1$190b4d59$TocWPHqN/iCLdVI8y9BML.
Dec 11 17:12:50 sd-13047 authdaemond: Authenticated: sysusername=, sysuserid=1001, sysgroupid=1001, homedir=/var/mail/virtual/, address=seb@mondomaine.fr, fullname=, maildir=mondomaine.fr/seb@mondomaine.fr/, quota=2097152, options=
Dec 11 17:12:50 sd-13047 authdaemond: Authenticated: clearpasswd=monMotDePasse, passwd=$1$190b4d59$TocWPHqN/iCLdVI8y9BML.
-- Activer les logs MySQL à chaud sans redémarrer le serveur MySQL pour tracer les requêtes MySQL.
 
SELECT VERSION(), @@general_log, @@log_output, @@general_log_file;
5.1.58-1~dotdeb.0 	0 	FILE 	/var/run/mysqld/mysqld.log
 
SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = '/var/log/mysql/mysql.log';
 
SELECT @@general_log, @@log_output, @@general_log_file;
5.1.58-1~dotdeb.0 	1 	FILE 	/var/log/mysql/mysql.log
 
-- Tail -f /var/log/mysql/mysql.log
postfix/smtpd: warning: SASL authentication failure: cannot connect to saslauthd server: Permission denied et SASL LOGIN authentication failed: generic failure

Pour corriger ce problème, fouillez dans le vieux post : Debian : Postfix + MySQL + SASL + PostfixAdmin + Courier + VirtualDomain + Serveur de mail SMTP IMAP POP3

auth_rimap: unexpected response to auth request: * OK [ALERT] Filesystem notification initialization error -- contact your mail administrator (check for configuration errors with the FAM/Gamin library)

Si dans les logs, vous avez le message :

auth_rimap: unexpected response to auth request: * OK [ALERT] Filesystem notification initialization error -- contact your mail administrator (check for configuration errors with the FAM/Gamin library)

Lisez SASL PLAIN authentication failed: authentication failure ou Mail Story 1: Debian + Postfix (SMTP) + Courier (IMAP) + SSL

Une solution rapide pour remédier à ce problème est de compléter libfam avec FAM :

# apt-get install fam libfam0
Les paquets suivants seront ENLEVÉS :
 gamin libgamin0
Les NOUVEAUX paquets suivants seront installés :
 fam libfam0

soit de remplacer FAM avec Gamin :

# apt-get install gamin
Les paquets suivants seront ENLEVÉS :
 fam libfam0
Les NOUVEAUX paquets suivants seront installés :
 gamin libgamin0 libglib2.0-0 libglib2.0-data shared-mime-info

par exemple si l'installation de FAM vous pose problème :

Paramétrage de fam (2.7.0-17) ...
insserv: Service portmap has to be enabled to start service fam
insserv: exiting now!
update-rc.d: error: insserv rejected the script header
dpkg : erreur de traitement de fam (--configure) :

On relance ensuite les services :

/etc/init.d/saslauthd restart
/etc/init.d/postfix restart
/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop restart
 /etc/init.d/courier-pop-ssl restart