First things first. If you are a novice at linux I don't think you should be trying to set this up. This is an advanced email server configuration. This configuration will allow you to serve multiple domains on one server. You will get the following features:
This howto will be divided into the following goals. You'll have to do item 1. items 2, 3, and 4 can be mixed and matched.
Lets get started
> yum install pam-devel
Wouldn't you know it. the postfix rpm from fedora core does not include mysql support. So lets install the correct version.
> yum remove postfix
> rpm -ivh http://www.campworld.net/downloads/postfix-2.2.2-2.i386.rpm
; added for web-cyradm allow_call_time_pass_reference on
> nano -w conf.php
# The Cyrus login stuff
$CYRUS = array(
'HOST' => 'localhost',
'PORT' => 143,
'ADMIN' => 'cyrus',
'PASS' => 'secret'
);
$DB = array(
'TYPE' => 'mysql',
'USER' => 'mail',
'PASS' => 'secret',
'PROTO' => 'unix', // set to "tcp" for TCP/IP
'HOST' => 'localhost',
'NAME' => 'mail'
);
alias /webcyradm /usr/share/web-cyradm-0.5.4-1
<Directory /usr/share/web-cyradm-0.5.4-1>
php_flag allow_call_time_pass_reference on
</Directory>
auth sufficient pam_mysql.so user=mail passwd=secret host=localhost db=m ail table=accountuser usercolumn=username passwdcolumn=password crypt=1 logtable =log logmsgcolumn=msg logusercolumn=user loghostcolumn=host logpidcolumn=pid log timecolumn=time account required pam_mysql.so user=mail passwd=secret host=localhost db=m ail table=accountuser usercolumn=username passwdcolumn=password crypt=1 logtable =log logmsgcolumn=msg logusercolumn=user loghostcolumn=host logpidcolumn=pid log timecolumn=time
Fedora doesn't start saslauthd with the right flags. Edit /etc/init.d/saslauthd. Look for the line that says 'MECH=shadow'. Change it to say 'MECH=pam'.
Replace /etc/syscnfig/saslauthd with the following.
# Directory in which to place saslauthd's listening socket, pid file, and so # on. This directory must already exist. SOCKETDIR=/var/run/saslauthd # Mechanism to use when checking passwords. Run "saslauthd -v" to get a list # of which mechanism your installation was compiled to use. MECH=pam # Additional flags to pass to saslauthd on the command line. See saslauthd(8) # for the list of accepted flags. FLAGS=-r
First we need to set the password for the cyrus user. > passwd cyrus
Below you will see the config files you need to create. Be sure to change things such as the server name.
/etc/imapd.conf
postmaster: postmaster configdirectory: /var/lib/imap partition-default: /var/spool/imap admins: cyrus sievedir: /var/lib/imap/sieve sieve_maxscriptsize: 320 sieve_maxscripts: 5 unixhierarchysep: yes altnamespace: yes sendmail: /usr/sbin/sendmail hashimapspool: true sasl_pwcheck_method: saslauthd sasl_mech_list: PLAIN tls_cert_file: /etc/pki/cyrus-imapd/cyrus-imapd.pem tls_key_file: /etc/pki/cyrus-imapd/cyrus-imapd.pem tls_ca_file: /etc/pki/tls/certs/ca-bundle.crt allowanonymouslogin: no allowplaintext: yes allowplainwithouttls: yes autocreatequota: 10000 reject8bit: no quotawarn: 90 timeout: 30 poptimeout: 10 dracinterval: 0 drachost: localhost servername: host.example.com
/etc/imapd-local.conf
postmaster: postmaster configdirectory: /var/lib/imap partition-default: /var/spool/imap admins: cyrus sievedir: /var/lib/imap/sieve sieve_maxscriptsize: 32 sieve_maxscripts: 5 unixhierarchysep: yes sendmail: /usr/sbin/sendmail hashimapspool: true sasl_pwcheck_method: saslauthd sasl_mech_list: PLAIN tls_cert_file: /etc/pki/cyrus-imapd/cyrus-imapd.pem tls_key_file: /etc/pki/cyrus-imapd/cyrus-imapd.pem tls_ca_file: /etc/pki/tls/certs/ca-bundle.crt allowanonymouslogin: no allowplaintext: yes autocreatequota: 10000 reject8bit: no quotawarn: 90 timeout: 30 poptimeout: 10 dracinterval: 0 drachost: localhost servername: host.example.com
/etc/cyrus.conf
# standard standalone server implementation
START {
# do not delete this entry!
recover cmd="ctl_cyrusdb -r"
# this is only necessary if using idled for IMAP IDLE
idled cmd="idled"
}
# UNIX sockets start with a slash and are put into /var/lib/imap/sockets
SERVICES {
# add or remove based on preferences
imap cmd="imapd" listen="imap" prefork=5
imaps cmd="imapd -s" listen="imaps" prefork=1
pop3 cmd="pop3d" listen="pop3" prefork=3
pop3s cmd="pop3d -s" listen="pop3s" prefork=1
sieve cmd="timsieved" listen="sieve" prefork=1
# these are only necessary if receiving/exporting usenet via NNTP
# nntp cmd="nntpd" listen="nntp" prefork=3
# nntps cmd="nntpd -s" listen="nntps" prefork=1
# at least one LMTP is required for delivery
# lmtp cmd="lmtpd" listen="lmtp" prefork=0
lmtpunix cmd="lmtpd" listen="/var/lib/imap/socket/lmtp" prefork=1
# this is only necessary if using notifications
# notify cmd="notifyd" listen="/var/lib/imap/socket/notify" proto="udp" prefork=1
}
EVENTS {
# this is required
checkpoint cmd="ctl_cyrusdb -c" period=30
# this is only necessary if using duplicate delivery suppression,
# Sieve or NNTP
delprune cmd="cyr_expire -E 3" at=0400
# this is only necessary if caching TLS sessions
tlsprune cmd="tls_prune" at=0400
}
Here we go with more config files. You'll have to be sure to change some settings to match your host. The config files will have sections commented out. Don't worry about it. These sections are for spam/virus/sympa configuration. Just copy and past to create the config files. What ever you see here replaces what already exists.
/etc/postfix/main.cf
# postfix user/group
#soft_bounce=yes
mail_owner = postfix
setgid_group = postdrop
delay_warning_time = 4
# postfix paths
html_directory = no
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
queue_directory = /var/spool/postfix
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.2.2/samples
readme_directory = /usr/share/doc/postfix-2.2.2/README_FILES
# network settings
inet_interfaces = all
mydomain = yourdomain.com
myhostname = host.yourdomain.com
mynetworks = 192.168.0.0/16,
127.0.0.0/24,
69.239.170.72/29
mydestination = $myhostname,
localhost.$mydomain,
localhost,
mysql:/etc/postfix/mysql-mydestination.cf
relay_domains = $mydestination
# mail delivery
local_transport = cyrus
mailbox_transport = cyrus
recipient_delimiter = +
# mappings
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
sender_canonical_maps = mysql:/etc/postfix/mysql-canonical.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual.cf,
regexp:/etc/postfix/virtual_regexp
transport_maps = mysql:/etc/postfix/mysql-transport.cf,
regexp:/etc/postfix/transport_regexp
#local_recipient_maps =
# sympa parameters
# sympa_destination_recipient_limit = 1
# sympabounce_destination_recipient_limit = 1
# debugging
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
# authentication
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
broken_sasl_auth_clients = yes
# rules restrictions
# smtpd_client_restrictions = reject_rbl_client sb1.spamhaus.org
smtpd_helo_restrictions = permit_sasl_authenticated,
permit_mynetworks,
reject_non_fqdn_hostname
smtpd_sender_restrictions = reject_non_fqdn_sender,
reject_unknown_sender_domain
smtpd_recipient_restrictions = permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain
smtpd_helo_required = yes
unknown_local_recipient_reject_code = 550
disable_vrfy_command = yes
smtpd_data_restrictions = reject_unauth_pipelining
/etc/postfix/master.cf
#
# Postfix master process configuration file. For details on the format
# of the file, see the Postfix master(5) manual page.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n - n - - smtpd
# -o content_filter=smtp-amavis:127.0.0.1:10024
# -o receive_override_options=no_address_mappings
#submission inet n - n - - smtpd
# -o smtpd_etrn_restrictions=reject
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#smtps inet n - n - - smtpd
# -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes
#submission inet n - n - - smtpd
# -o smtpd_etrn_restrictions=reject
# -o smtpd_enforce_tls=yes -o smtpd_sasl_auth_enable=yes
#628 inet n - n - - qmqpd
pickup fifo n - n 60 1 pickup
-o content_filter=
-o receive_override_options=no_header_body_checks
cleanup unix n - n - 0 cleanup
qmgr fifo n - n 300 1 qmgr
#qmgr fifo n - n 300 1 oqmgr
tlsmgr unix - - n 1000? 1 tlsmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
defer unix - - n - 0 bounce
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
smtp unix - - n - - smtp
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay unix - - n - - smtp
-o fallback_relay=
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - n - - showq
error unix - - n - - error
discard unix - - n - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent. See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
#
# The Cyrus deliver program has changed incompatibly, multiple times.
#
old-cyrus unix - n n - - pipe
flags=R user=cyrus argv=/usr/lib/cyrus-imapd/deliver -e -m ${extension} ${user}
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
cyrus unix - n n - - pipe
user=cyrus argv=/usr/lib/cyrus-imapd/deliver -r ${sender} -m ${extension} ${user}
#
# See the Postfix UUCP_README file for configuration details.
#
uucp unix - n n - - pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail unix - n n - - pipe
flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp unix - n n - - pipe
flags=Fq. user=foo argv=/usr/local/sbin/bsmtp -f $sender $nexthop $recipient
#
# spam/virus section
#
#smtp-amavis unix - - y - 2 smtp
# -o smtp_data_done_timeout=1200
# -o disable_dns_lookups=yes
# -o smtp_send_xforward_command=yes
#127.0.0.1:10025 inet n - y - - smtpd
# -o content_filter=
# -o smtpd_helo_restrictions=
# -o smtpd_sender_restrictions=
# -o smtpd_recipient_restrictions=permit_mynetworks,reject
# -o mynetworks=127.0.0.0/8
# -o smtpd_error_sleep_time=0
# -o smtpd_soft_error_limit=1001
# -o smtpd_hard_error_limit=1000
# -o receive_override_options=no_header_body_checks
# -o smtpd_bind_address=127.0.0.1
# -o smtpd_helo_required=no
# -o smtpd_client_restrictions=
# -o smtpd_restriction_classes=
# -o disable_vrfy_command=no
# -o strict_rfc821_envelopes=yes
#
# transport entry for the mailing lists
#
#sympa unix - n n - - pipe
# flags=R user=sympa argv=/home/sympa/bin/queue ${recipient}
#sympabounce unix - n n - - pipe
# flags=R user=sympa argv=/home/sympa/bin/bouncequeue ${user}
/usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd mech_list: plain login
/etc/postfix/mysql-canonical.cf
# mysql config file for canonical lookups on postfix # comments are ok. # # the user name and password to log into the mysql server hosts = 127.0.0.1 user = mail password = secret # the database name on the servers dbname = mail # the table name table = virtual # select_field = alias where_field = username # Return the first match only additional_conditions = and status = '1' limit 1
/etc/postfix/mysql-mydestination.cf
# mysql config file for local domain (like sendmail's sendmail.cw) lookups on postfix # comments are ok. # # the user name and password to log into the mysql server hosts = 127.0.0.1 user = mail password = secret # the database name on the servers dbname = mail # the table name table = domain # select_field = domain_name where_field = domain_name
/etc/postfix/mysql-relay.cf
# # mysql config file for transport lookups on postfix # comments are ok. # # the user name and password to log into the mysql server hosts = 127.0.0.1 user = mail password = secret # the database name on the servers dbname = mail # the table name table = domain # select_field = transport where_field = domain_name
/etc/postfix/mysql-transport.cf
# # mysql config file for transport lookups on postfix # comments are ok. # # the user name and password to log into the mysql server hosts = 127.0.0.1 user = mail password = secret # the database name on the servers dbname = mail # the table name table = domain # select_field = transport where_field = domain_name
/etc/postfix/mysql-virtual.cf
# # mysql config file for alias lookups on postfix # comments are ok. # # the user name and password to log into the mysql server hosts = 127.0.0.1 user = mail password = secret # the database name on the servers dbname = mail # the table name table = virtual # select_field = dest where_field = alias additional_conditions = and status = '1'
/etc/postfix/transport_regexp
# /^.*+owner\@lists\..*$/ sympabounce: # /^.*\@lists\..*$/ sympa:
/etc/postfix/virtual_regexp
# This will be used to deal with the mailing lists #/^(.*)-owner\@lists\.(.*)$/ $1+owner@lists.$2
Be sure your /etc/hosts looks similar to the following.
# Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost 192.168.11.21 host.domain.com
First things first. Reboot the system. If everything went well we all should be at the same point. We need to start some services that are not started yet.
> /etc/init.d/cyrus-imap start
> /etc/init.d/saslauthd start
No errors? Lets keep going. Log into webmin or use ntsysv and set saslauthd and cyrus-imap to start on boot.
Setup a test domain and account. Setup your favorit mail client and send some test emails.
We should next give our users a web interface to their mail. This is an optional install.
The program we're going to install is SquirrelMail. So just type:
>yum install squirrelmail
The easy part is over. Now we need to do some configuration. Luckilly squirrelmail has a configuration utility. So type: > /usr/share/squirrelmail/config/conf.pl
Here's the settings to be changed
You should now be able to login to your mailserver. The usr would be 'host.domain.com/webmail'. Remember your username is in the format: user.domain.com
This is another optional item. I suggest that you install this as well.
Do the following:
> yum install amavisd-new clamav clamav-update spamassassin
Type
> nano -w /etc/freshclam.conf
The line that has the word example on it needs to be commented out or deleted. The config file explaines.
Let's bring the virus definiations up to date.
> freshclam
You need to register to use Razor. So type the following.
> razor-admin -register -user=some_user -pass=somepass
You need to edit /etc/amavisd/amavisd.conf
Here is a list of items you should change. just scroll through the file to find each item.
Here are some settings I added in. Use them if you wish.
# added in settings RC
@whitelist_sender_maps = read_hash("$MYHOME/white.lst");
@blacklist_sender_maps = read_hash("$MYHOME/black.lst");
$spam_quarantine_to = "spam\@$mydomain";
$virus_quarantine_to = "virus\@$mydomain";
$banned_quarantine_to = "spam\@$mydomain";
$hdrfrom_notify_admin = "Content Filter <postmaster\@$mydomain>";
Since I have white and black list files they need to be created.
> touch /var/spool/amavisd/black.lst
> touch /var/spool/amavisd/white.lst
> chown amavis:amavis /var/spool/amavisd/black.lst
> chown amavis:amavis /var/spool/amavisd/white.lst
Let's start amavisd
> /etc/init.d/amavisd start
We need to tell postfix about amavisd. If you copied and pasted the postfix files from abouve than you are in good shape. All we need to do is uncomment some lines.
Uncomment the two lines below the smtp
smtp inet n - n - - smtpd # -o content_filter=smtp-amavis:127.0.0.1:10024 # -o receive_override_options=no_address_mappings
OK. Restart postfix
> /etc/init.d/postfix restart
Now send yourself some test emails. Lets hope it went well.
I've used both mailman and sympa. Both are good and bad. Neither of them have all the features I want. I decided to use mailman. It will at least meet my modest needs. It kinda handles virtual domains. The mailing list names must be unique. Well lets get started.
Just type the following
> yum install mailman
We are going to do a setup that dowsn't require you to modify postfix files for every list. I found the following script. It contains all the info we need. Past the following into a file called /var/lib/mailman/bin/postfix-to-mailman.py
#! /usr/bin/env python
# Configuration variables - Configured for Fedora Core 4.
MailmanHome = "/usr/bin/mailman"; # Mailman home directory.
MailmanOwner = "postmaster@example.com"; # Postmaster and abuse mail recepient.
# End of configuration variables.
# postfix-to-mailman.py
#
# Interface mailman to a postfix with a mailman transport. Does not require
# the creation of _any_ aliases to connect lists to your mail system.
#
# Richard Camp, richard@campworld.net, Feb 2005.
# updated to fedora core and to work with the howto
#
# Dax Kelson, dkelson@gurulabs.com, Sept 2002.
# coverted from qmail to postfix interface
#
# Lee Marzke, lee@marzke.net, Nov 2003
# updated for Mailman 2.1
#
# This script was originally qmail-to-mailman.py by:
# Bruce Perens, bruce@perens.com, March 1999.
# This is free software under the GNU General Public License.
#
# This script is meant to be called from ~mailman/postfix-to-mailman.py.
# It catches all mail to a virtual domain, eg "lists.example.com".
# It looks at the recepient for each mail message and decides if the mail is
# addressed to a valid list or not, and bounces the message with a helpful
# suggestion if it's not addressed to a list. It decides if it is a posting,
# a list command, or mail to the list administrator, by checking for the
# -admin, -owner, and -request addresses. It will recognize a list as soon
# as the list is created, there is no need to add _any_ aliases for any list.
# It recognizes mail to postmaster, mailman-owner, abuse, mailer-daemon, root,
# and owner, and routes those mails to MailmanOwner as defined in the
# configuration variables, above.
#
# INSTALLATION:
#
# Install this file as ~mailman/postfix-to-mailman.py
#
# To configure a virtual domain to connect to mailman, edit Postfix thusly:
#
# /etc/postfix/main.cf:
# relay_domains = ... lists.example.com
# mailman_destination_recipient_limit = 1
#
# /etc/postfix/transport_regexp:
# /^.*\@lists\..*$/ mailman:
#
# /etc/postfix/master.cf
# mailman unix - n n - - pipe
# flags=FR user=mailman:mailman
# argv=/var/mailman/postfix-to-mailman.py ${nexthop} ${mailbox}
#
#
# Note that _all_ mail to that domain will go to Mailman, so you
# don't want to put the name of your main domain here. Typically a virtual
# domain lists.domain.com is used for Mailman, and domain.com for regular
# email.
#
import sys, os, re, string
def main():
os.nice(5) # Handle mailing lists at non-interactive priority.
# delete this if you wish
os.chdir(MailmanHome + "/lists")
try:
local = sys.argv[2]
except:
# This might happen if we're not using Postfix
sys.stderr.write("LOCAL not set?\n")
sys.exit(1)
local = string.lower(local)
local = re.sub("^mailman-","",local)
names = ("root", "postmaster", "mailer-daemon", "mailman-owner", "owner",
"abuse")
for i in names:
if i == local:
os.execv("/usr/sbin/sendmail",
("/usr/sbin/sendmail", MailmanOwner))
sys.exit(0)
type = "post"
types = (("-post$" , "post"),
("-admin$" , "admin"),
("-bounces$", "bounces"),
("-confirm$", "confirm"),
("-join$" , "join"),
("-leave$" , "leave"),
("-owner$" , "owner"),
("-request$", "request"),
("-subscribe$", "subscribe"),
("-unsubscribe$", "unsubscribe"))
for i in types:
if re.search(i[0],local):
type = i[1]
local = re.sub(i[0],"",local)
if os.path.exists(local):
os.execv(MailmanHome + "/mail/mailman",
(MailmanHome + "/mail/mailman", type, local))
else:
bounce()
sys.exit(75)
def bounce():
bounce_message = """\
TO ACCESS THE MAILING LIST SYSTEM: Start your web browser on
http://%s/
That web page will help you subscribe or unsubscribe, and will
give you directions on how to post to each mailing list.\n"""
sys.stderr.write(bounce_message % (sys.argv[1]))
sys.exit(1)
try:
sys.exit(main())
except SystemExit, argument:
sys.exit(argument)
except Exception, argument:
info = sys.exc_info()
trace = info[2]
sys.stderr.write("%s %s\n" % (sys.exc_type, argument))
sys.stderr.write("Line %d\n" % (trace.tb_lineno))
sys.exit(75) # Soft failure, try again later.
Add the following line to /etc/postfix/main.cf
mailman_destination_recipient_limit = 1
Add the following lines to /etc/postfix/master.cf
mailman unix - n n - - pipe
flags=FR user=mailman:mailman
argv=/var/mailman/postfix-to-mailman.py ${nexthop} ${mailbox}
Add the following line to /etc/postfix/transport_regexp
/^.*\@lists\..*$/ mailman:
Now lets create the site mailing list. Type the following
> cd /usr/lib/mailman
> bin/newlist mailman
> bin/config_list -i /var/lib/mailman/data/sitelist.cfg mailman
Be sure to go through the web and modify settings as needed.
Now create the site wide passowrd
> cd /usr/lib/mailman
> bin/mmsitepass <your-site-password>
Ok now start everything up
> /etc/init.d/mailman start
With a bit of work you come out with a robust server.