Introduction

This page describes site-specific configure of various mail services. The actual installation of postfix, etc is covered by MDI.

Procedure

SMTP

  1. On all systems, complete the following general sub-procedure:
    1. Edit /etc/dovecot/dovecot.conf and set:

      protocols = none
      #log_path = ... 
    2. Run:

      service dovecot restart 
    3. Edit /etc/postfix/main.cf to contain only:

      #mynetworks = ...
      #  mynetworks is limited to this host itself (mynetworks defines priviliged clients)
      mynetworks_style = host
      #  what NICs do I listen for client connections on?
      inet_interfaces = loopback-only
      #  this will affect message IDs
      myhostname = <fully-qualified-hostname>
      #  this will affect what's on the right of '@' in unqualified From: addresses
      myorigin = /etc/mailname
      smtpd_recipient_restrictions = reject
      smtpd_helo_required = yes
      smtpd_helo_restrictions = reject
      local_header_rewrite_clients = permit_inet_interfaces
      masquerade_classes = envelope_sender, header_sender, header_recipient
      alias_maps = hash:/etc/aliases
      alias_database = hash:/etc/aliases
      mailbox_size_limit = 0 
    4. Run:

      service postfix restart 

      (This is needed if inet_interfaces changes.)

  2. To configure delivery of all email to go to a smart host on the local network, complete the following sub-procedure:
    1. Add the following to /etc/postfix/main.cf:

      #  this is needed so upstream masquerader recognises our mails as to be masqueraded
      append_dot_mydomain = yes
      #smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
      #smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
      #smtpd_use_tls = yes
      #smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
      #smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
      #  don't accept anything for local delivery
      mydestination =
      relayhost = <fully-qualified-hostname-of-smart-host> 
    2. Run:

      postfix reload 
    3. Test by running:

      tail -f /var/log/mail.info &
      date | mailx <remote-address> 
  3. To configure direct delivery of internet-bound email, complete the following sub-procedure:
    1. Add the following to /etc/postfix/main.cf:

      #  I'm not sure if this is needed or not - will confirm later
      #append_dot_mydomain = no
      #smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
      #smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
      #smtpd_use_tls = yes
      #smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
      #smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
      #  mails to this host will be delivered locally
      mydestination = localhost, $myhostname
      #  everything else will go direct, not via a relay 
    2. Run:

      postfix reload 
  4. To configure delivery of internet-bound email to go via a remote smart host, complete the following sub-procedure:
    1. Add the following to /etc/postfix/main.cf:

      #  next line not verified
      append_dot_mydomain = no
      smtp_sasl_auth_enable = yes
      smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
      smtp_sasl_security_options =
      #  mails to this host will be delivered locally
      mydestination = localhost, $myhostname
      #  everything else to be relayed via here
      relayhost = <fully-qualified-hostname-of-smart-host> 
    2. Edit /etc/postfix/sasl_passwd and add an entry of the format:

      <name-of-upstream-mail-relay> <login>:<password> 
    3. "Compile" the config file by running:

      postmap hash:/etc/postfix/sasl_passwd 
    4. Edit /etc/mailname and put your publicly meaningful hostname in there.
    5. Run:

      postfix reload 
    6. Test by running:

      tail -f /var/log/mail.info &
      date | mailx <remote-address> 
  5. To configure reception of email from the internet, but only for delivery into local mailboxes, complete the following sub-procedure:
    1. Install the following packages and their prerequisites:
      • postgrey
    2. Edit /etc/default/postgrey and change the definition of POSTGREY_OPTS as below:

      POSTGREY_OPTS="--inet=127.0.0.1:10023" 
    3. Run:

      service postgrey restart 
    4. Add the following to /etc/postfix/main.cf:

      mailbox_command = /usr/lib/dovecot/deliver 
    5. Change the following in /etc/postfix/main.cf:

      inet_interfaces = all
      smtpd_recipient_restrictions = reject_unauth_destination, reject_rbl_client zen.spamhaus.org, reject_rbl_client list.dsbl.org, reject_rbl_client bl.spamcop.net, check_policy_service inet:127.0.0.1:10023, permit
      smtpd_helo_restrictions = reject_invalid_helo_hostname, reject_unknown_helo_hostname
      mydestination = ..., <fully-qualified-hostname-of-this-machines-name-as-seen-by-the-internet> 
      (There are already definitions for 'smtpd_recipient_restrictions' and 'smtpd_helo_restrictions'; change the entire lines. There is already a definition for 'mydestination'; just add the specified value to it.)
    6. Run:

      service postfix restart 

      (This is needed if inet_interfaces changes.)

    7. Test by running:

      tail -f /var/log/mail.info &
      ssh <remote-machine> 
      date | mailx <local-address> 
      Mails should bounce but only because delivery into local mailboxes is not configured, not because the mail is not accepted.
  6. To configure reception of email from authenticated email clients (be they local or remote, be they for delivery into local mailboxes or for relaying), complete the following sub-procedure:
    1. Add the following to /etc/postfix/main.cf:

      smtpd_sasl_type = dovecot
      smtpd_sasl_path = private/auth
      smtpd_sasl_auth_enable = yes 
    2. Change the following in /etc/postfix/main.cf:

      smtpd_recipient_restrictions = permit_sasl_authenticated, ...
      smtpd_helo_restrictions = permit_sasl_authenticated, ... 
      Note that these 'permit' values must appear first in the list of values on the right hand side of the '=', otherwise other 'reject' values may be applied first (e.g. 'reject_unauth_destination').
    3. Run:

      postfix reload 
    4. Edit /etc/dovecot/dovecot.conf, locate the block:

      auth default {
          ...
      } 

      and insert inside it:

      mechanisms plain login
      ...
      socket listen {
          client {
              path = /var/spool/postfix/private/auth
              mode = 0660
              user = postfix
              group = postfix
          }
      } 
    5. Run:

      service dovecot restart 
    6. Test by sending a mail from a remote client, with the SMTP server defined as this one. (Beware that firewall policies on the machine you are sending from may mean that your server is not reachable on port 25.) Mails should bounce but only because delivery into local mailboxes is not configured, not because the mail is not accepted.
  7. To configure reception of email from the local network (using qualified or unqualified addresses, be they for delivery into local mailboxes or for relaying), complete the following sub-procedure:
    1. Add the following to /etc/postfix/main.cf:

      masquerade_domains = $mydomain 
    2. Change the following in /etc/postfix/main.cf:

      mynetworks_style = subnet
      #  accept for local delivery emails with To: address user@anything.my.domain
      mydestination = ..., $mydomain
      local_header_rewrite_clients = permit_mynetworks
      smtpd_recipient_restrictions = ... permit_mynetworks ...
      smtpd_help_restrictions = ... permit_mynetworks ...
      masquerade_classes = ... envelope_recipient, ... 
      Note that these 'permit' values must appear first in the list of values on the right hand side of the '=', otherwise other 'reject' values may be applied first (e.g. 'reject_unauth_destination').
    3. Run:

      postfix reload 
    4. Test by sending a mail from a local client, with the SMTP server defined as this one and deliberately not providing any authentication. Mails should bounce but only because delivery into local mailboxes is not configured, not because the mail is not accepted.
  8. To configure the handling of email for local mailboxes by dovecot, complete the following sub-procedure:
    1. Change the following in /etc/dovecot/dovecot.conf:

      mail_location = maildir:/var/mail/maildir/%u:INDEX=/var/mail/indexes/%u 
    2. If you need to allocate storage for this then do so now.
    3. Edit /etc/dovecot/dovecot.conf, locate the block:

      #protocol lda {
      ...
      #} 

      and uncomment it and the following elements in it:

      protocol lda {
          postmaster_address = alexis@dione.no-ip.org
          auth_socket_path = /var/run/dovecot/auth-master
      } 
    4. Edit /etc/dovecot/dovecot.conf, locate the block:

      auth default {
          socket listen {
              ...
          }
      } 

      and insert inside it:

      master {
          path = /var/run/dovecot/auth-master
          mode = 0600
          user =
          group =
      } 
    5. Run:

      service dovecot restart 
    6. Add the following to /etc/postfix/main.cf:

      mailbox_command = /usr/lib/dovecot/deliver 
    7. Run:

      postfix reload 
    8. If necessary run:

      mkdir -p /var/mail/{maildir,indexes}
      chmod 1777 /var/mail/{maildir,indexes} 
    9. Test by sending a mail and verify it arrives in /var/mail/{maildir,indexes}. (You still will not be able to use an IMAP mail client to read your mail as IMAP access has not yet been enabled.)
  9. Edit /etc/aliases and add a suitable for root and then run:

    newaliases 

IMAP

  1. To configure retrieval of emails from local mailboxes via IMAP, complete the following sub-procedure:
    1. If the IMAP server will access mailbox files via NFS then change the following in /etc/dovecot/dovecot.conf:

      mmap_disable = yes
      fsync_disable = no
      mail_nfs_storage = yes
      mail_nfs_index = yes 
    2. Change the following in /etc/dovecot/dovecot.conf:

      protocols = imaps 
    3. Run:

      service dovecot restart 
    4. Test by accessing the mailboxes via IMAP.

Mailman

Much of this is taken from http://www.debian-administration.org/articles/108.

  1. Run:

    apt-get install mailman 

    This will generate the following output:

    Site list for mailman missing (looking for list named 'mailman'). (warning).
    Please create it; until then, mailman will refuse to start. (warning). 
  2. The above errors are because installation of mailman does not create the any mailing lists but one specific list is required. Create this now by running:

    newlist mailman 

    and when prompted enter your own email address as list admin and set a password for the list. A list of aliases will be written to standard output, like this:

    ## mailman mailing list
    mailman:              "|/var/lib/mailman/mail/mailman post mailman"
    mailman-admin:        "|/var/lib/mailman/mail/mailman admin mailman"
    ... 
  3. Copy that entire alias list into /etc/aliases and run:

    newaliases 
  4. Now mailman can be started successfully by running:

    service mailman start 
  5. Check that the web interface is accessible by visiting http://<your-mail-server>/cgi-bin/mailman/listinfo.

Migrating mailing lists from an old mail server

  1. On the old mail server run:

    cd /var/lib/mailman
    tar cf /tmp/old.tar archive lists 
  2. Copy the tar file over to the new system and run:

    cd /var/lib/mail
    mv archive archive.old
    mv lists lists.old
    tar xf /tmp/old.tar 

Creating mailing lists

The procedure above was to install mailman. This procedure is for creating mailing lists.

  1. Determine the following:
    1. name of the list to create,
    2. email address of the list administrator (this is probably the address of the person requesting creation of the list),
    3. the hostname part of the mailman access URL; this might be <your-web-server> or <your-mail-server> or some 'dyndns' hostname, depending on your local setup (e.g. for me this is dione.no-ip.org). We'll refer to this as <web-server-hostname>,

    4. the hostname part of the email addresses for the lists; this might be <your-domain> or some 'dyndns' hostname, depending on your local setup (e.g. for me this is dione.no-ip.org). We'll refer to this as <mail-server-hostname>.

  2. Create a mailing list by running:

    newlist --urlhost=<web-server-hostname> --emailhost=< <list-name> 

    and when prompted enter the email address of the list admin and set a password for the list. A list of aliases will be written to standard output, like this:

    ## foo mailing list
    foo:              "|/var/lib/mailman/mail/mailman post foo"
    foo-admin:        "|/var/lib/mailman/mail/mailman admin foo"
    ... 
  3. Copy the entire alias list into /etc/aliases and run:

    newaliases 
  4. Visit http://<web-server-hostname>/cgi-bin/mailman/admin/<list-name> and adjust the privacy options.

Miscellaneous

  1. If the mail server is a replacement, then compare the mail configuration with the old system's mail configuration.

See also


CategoryProcedure

ConfiguringMailServices (last edited 2011-12-16 08:32:43 by AlexisHuxley)