A flag icon shows that page is written in: English, Japanese

Email Setup


POP3, POP3s, IMAP4, IMAP4s and SMTPs are used for transfers between a server and a client. Note the mail servers are actually communicating in plain SMTP protocol.

ProtocolTCP Port
POP3110
POP3s995
IMAP4143
IMAP4s993
SMTP25/587
SMTPs465

You will need to use S/MIME or other programs like PGP or GnuPG to encrypt the message itself.

StartTLS (STLS) : we never have to use this.

SMTP

What an SMTP server says:

220 mail.run.sh ESMTP
HELO run.sh
250 Hello run.sh, pleased to meet you
MAIL FROM:<taro@gihyo.co.jp>
250 taro@gihyo.co.jp.. Sender ok
RCPT TO:<hanako@muf.biglobe.ne.jp>
250 Recipient ok
DATA
354 Enter mail. end with "." on a line by itself
Date:
From:
To:
Subject:

Is this your first visit to Japan?
.
250 Message accepted for delivery
QUIT
221 mail.run.sh closing connection
Errors
421service not available
554SMTP synchronization error

qmail SMTP Server

qmail used to be a quicker solution than sendmail, although these days Exim4 which is explained below and Postfix which is default in many distros are much more popular for their compatibilities with other modules and programs.

To receive emails in which the host name of recipient addresses is omitted (e.g. user@domain.com instead of user@host.domain.com), add your domain name to the files :

/var/qmail/control/locals
/var/qmail/control/rcpthosts

Exim4 SMTP Server

Whenever you're sure what you are doing, go for the split config so that the default configurations that come with a package like mailman can go into the 'conf.d' directory.

In either case, remember that the exim daemon needs restarting before it sees configuration changes.

This is because, since Exim (version 3) rereads its configuration on every delivery attempt, it is unadvisable to edit a live configuration file. If you're using Debian and 4.x, the config it uses isn't the one you edit (it gets generated on init-script-reload), so you're OK.

If you are using unsplit configuration, have local changes to /etc/exim4/conf.d/ (either made by yourself or by other packages dropping their own routers or transports in) and want to re-generate /etc/exim4/exim4.conf.template to activate these changes, you can do so by using 'update-exim4.conf.template'.

$ sudo dpkg-reconfigure exim4-config

Follow this example for initial configuration of Exim4 :

Mail name run.sh
IP addresses to listen to [blank]- which in fact means everywhere
Local domains run.sh
Recipient domains to relay mails for [blank]
IP addresses for a smarthost to relay mails for [blank]
Keep dial-on-demand minimal No
Delivery method for local mail Maildir in home directory
Split configuration into small files? Yes

IMAP/POP Server

Dovecot

Edit '/etc/dovecot/dovecot.conf' :

protocols = imap imaps pop3 pop3s

Mailing List Setup

Mailman 2.1.11 is superior in web integration than majordomo.

$ sudo aptitude install mailman exim4-daemon-heavy libapache2-mod-php5

To use this with Exim4, you should read through :

$ less /usr/share/doc/mailman/README.Exim4.Debian

Before configuring, the mailing list server is turned off by default.

Apache2

Make a symlink to the example Apache configuration in /etc/mailman/ from the web site config dedicated for Mailman :

$ sudo ln -s /etc/mailman/apache.conf /etc/apache2/conf.d/mailman

And edit the head of /etc/apache2/conf.d/mailman :

# We can find mailman here:
ScriptAlias /mailman/ /usr/lib/cgi-bin/mailman/
# And the public archives:
Alias /pipermail/ /var/lib/mailman/archives/public/
# Logos:
Alias /images/mailman/ /usr/share/images/mailman/

Mailman

Edit '/etc/mailman/mm_cfg.py' and change the URL settings according to the Apache2 configuration you've made above.

If you're not going to support virtual domain with Mailman, you should skip some steps which are listed in /usr/share/doc/mailman/README.Exim4.Debian. BTW, I would like to change the default web interface URL pattern so let's take the following changes in /etc/mailman/mm_cfg.py :

DEFAULT_URL_PATTERN = 'http://%s/mailman/'
PRIVATE_ARCHIVE_URL = '/mailman/private'
IMAGE_LOGOS = '/images/mailman/'

DEFAULT_EMAIL_HOST = 'run.sh'
DEFAULT_URL_HOST = 'mail.run.sh'

DEFAULT_REPLY_GOES_TO_LIST = 1

If you're sure you don't need anything on virtual domains, you can just set :

MTA='None'

and skip these Postfix style virtual domain settings shown below :

MTA='Postfix'
POSTFIX_ALIAS_CMD = '/bin/true'
POSTFIX_MAP_CMD = '/usr/local/bin/chgrp Debian-exim'
POSTFIX_STYLE_VIRTUAL_DOMAINS = [ 'run.sh' ]

If you use the above mapping, you should give a setuid bit to the 'chgrp' that is just copied from /bin directory, and make it executable only for root and the group that the web server runs as.

$ sudo cp /bin/chgrp /usr/local/bin
$ sudo chmod 4750 /usr/local/bin/chgrp
$ sudo chown root:www-data /usr/local/bin/chgrp

Next, setup Mailman site password and list creator password with the following commands:

$ sudo mmsitepass
$ sudo mmsitepass -c

Create the system list for mailman :

$ sudo newlist mailman
$ sudo /usr/lib/mailman/bin/mailmanctl restart

Exim

The Exim configuration is built so that a list created within Mailman automatically appears to Exim without the need for defining any additional aliases (however Mailman may helpfully show or email you a list of required aliases when you create a list - you can just ignore those - if you have set the MTA parameter above it will stop doing this).

You also need to have an alias for mailman within the mm_domains, this picks up mail sent to the site list (or basically just sent in error), and should forward to the Mailman Administrator (it also has to be aliased as mailman-admin).

You will need to add some macros to the main section of your Exim config file. You will also need to define one new transport and add new routers. Additional ACLs may be used to handle policy enforcement.

Put this in your exim4 main configuration i.e. /etc/exim4/exim4.conf.template for unsplit configure, or files located in /etc/exim4/conf.d/*/ for split handling. If you use a split config, then for example '/etc/exim4/conf.d/main/50_local_mailman_macros' :

# Home dir for your Mailman installation -- aka Mailman's prefix
# directory.
MAILMAN_HOME=/var/lib/mailman
MAILMAN_WRAP=MAILMAN_HOME/mail/mailman

# User and group for Mailman, should match your --with-mail-gid
# switch to Mailman's configure script.
MAILMAN_USER=list
MAILMAN_GROUP=daemon

Put this in your exim4 router configuration. If you use a split config, then for example '/etc/exim4/conf.d/router/950_local_mailman' :

# Messages get sent out with
# envelope from "mailman-bounces@virtual_domain"
# But mailman doesn't put such addresses
# in the aliases. Recognise these here.
mailman_workaround:
  domains = +local_domains
  require_files = MAILMAN_HOME/lists/$local_part/config.pck
  driver = accept
  local_parts = mailman
  local_part_suffix_optional
  local_part_suffix = -bounces : -bounces+* : \
    -confirm+* : -join : -leave : \
    -subscribe : -unsubscribe : \
    -owner : -request : -admin
  transport = mailman_transport
  group = MAILMAN_GROUP

# Mailman lists
mailman_router:
  domains = +local_domains
  require_files = MAILMAN_HOME/lists/$local_part/config.pck
  driver = accept
  local_part_suffix_optional
  local_part_suffix = -bounces : -bounces+* : \
    -confirm+* : -join : -leave : \
    -subscribe : -unsubscribe : \
    -owner : -request : -admin
  transport = mailman_transport
  group = MAILMAN_GROUP

Here we don't need the line below, remember to remove this if you have set it :

  condition = \
  ${lookup{$local_part@$domain}\
  lsearch{MAILMAN_HOME/data/virtual-mailman}{1}{0}}

Put this in your exim4 transport configuration. If you use a split config, then for example '/etc/exim4/conf.d/transport/50_local_mailman' :

mailman_transport:
  driver = pipe
  command = MAILMAN_WRAP \
    '${if def:local_part_suffix \
      {${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
      {post}}' \
    $local_part
  current_directory = MAILMAN_HOME
  home_directory = MAILMAN_HOME
  user = MAILMAN_USER
  group = MAILMAN_GROUP
  freeze_exec_fail = true

Enable the new configuration and let's restart all related services for activation :

$ sudo /etc/init.d/apache2 restart
$ sudo /etc/init.d/exim4 restart
$ sudo /etc/init.d/mailman start

Now, create a link to http://yourweb.sh/mailman/admin or you would probably bookmark it.

Remember you could always redo the Exim4 package configuration as necessary :

$ sudo dpkg-reconfigure exim4-config

Always watch the log file '/var/log/exim4/paniclog' for the typo you might have made in the above configuration.

Otsukaresama!

SpamAssassin

You can block emails with SpamAssassin. Edit /etc/default/spamassassin

$ sa-learn --spam ~/Maildir/.Junk/cur

DKIM

SMTP-AUTH in Exim4

Generate an Exim4 SSL certificate.

# /usr/share/doc/exim4-base/examples/exim-gencert

Now edit /etc/exim4/exim4.conf.template using your favorite text editor and uncomment the `plain_server' section.

Then create (or edit if it exists) /etc/exim4/exim4.conf.localmacros and add the line:

MAIN_TLS_ENABLE = true

To actually setup the users and passwords create /etc/exim4/passwd

Copy output from:

htpasswd -nd usernameforsmtp

And paste it in /etc/exim4/passwd

Repeat for any other logins you'd like to add.

Now you're done. Update your configuration and Restart Exim4:

# update-exim4.conf
# /etc/init.d/exim4 restart

If you use the split version of config files instead of monolithic one, the files to edit/create in the split config are:

`htpasswd' is used to create an HTTP user entry for Apache, but it can be used for SMTP-Auth as well.


Return Home En

Ryu: ryu@run.sh