How To Set Up A Mail Server..
How To Set Up A Mail Server..
com/docs/postfix/
Ubuntu + Postfix + Courier IMAP + MySQL + Amavisd-new + SpamAssassin + ClamAV + SASL + TLS +
SquirrelMail/Roundcube + Postgrey
Easy to follow howto on setting up a mail server with unlimited users and domains, with IMAP/Pop access, anti-spam, anti-virus, secure authentication, encrypted traffic, web mail
interface and more.
Based on an Ubuntu distribution platform, but instructions are distro generic. Examples are run on Amazon AWS ec2, but only for demonstration purposes.
9th edition
Author Ivar Abrahamsen
License: Respect (CC by-sa)
Last Update: 2009-12-17
Contact / Discuss
Contents
Editions
List of different versions of this document.
Introduction
Brief description of this document.
Aim
Research
Donate
Software
Which software packages are we using and why.
Installation
How to install all packages and which ones.
Distrobution
Base Install
Repositories
Packages
Configuration
Post install, what to configure for each section, with full command examples.
Firewall (Shorewall)
MTA (Postfix)
Database (MySQL)
Pop/IMAP (Courier)
Content Checks (amivisd-new)
Anti-Spam(SpamAssassin)
Anti-Virus (ClamAV)
Policy Check (PostGrey)
Authentication (SASL)
Encryption (TLS)
Webmail (SquirrelMail)
Administration (phpMyAdmin)
Data
Creating the basic stub of data, and how to add your own.
Add users and domains
Common SQL
Test
Testing and troubleshooting each element.
Common problems
Test strategy
Switch debug on
Tail, tail and tail again
Telnet is your friend
Can postfix receive?
Can postfix send?
Can courier read?
Initialize
If receiving an already setup machine, a list of actions to do to initialize and configure it.
1 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Extend
Post working system, detailed instructions on optional features to add.
Remote MX mail backup
Local file backup
Sender ID & SPF
Spam Reporting
White/Black lists
PGP & S/MIME
Relocation notice
Pop-before-SMTP
Auto Reply
Block Addresses
Throttle Output
Mail Lists
Admin software
Google Apps / GMail
Maildrop, spam folder and vacation messaging
Roundcube webmail client
Appendix
About author
Contact
Why
References
Software Links
Difference between Ubuntu versions
Download
Todo
Change Log
FAQ
Return to top.
Editions
Edition State Started Updated Description
1st Released (outdated) 2004-01 2004-02 Based on Mandrake 9.1.
Based on Mandrake 10.x, but valid for all distributions. Very thorough. Includes package
description, where to get the sources and binaries, how to build them or which RPMs to use,
2nd Released (outdated) 2004-02 2004-07
includes many refrences, etc etc. Starts off with a basic working server, then advances,
extends and tightens it in stages.
Based on Ubuntu 5.04, Hoary Hedgehog. More concise simplified guide to get an advanced
3rd Released (outdated) 2005-05 2005-11
server working quickly. Now includes SASL & TLS integration.
4th Released 2005-10 2005-12 Based on Breezy Badger, Ubuntu 5.10. Includes Postgrey
5th Released (outdated) 2006-05 2006-11 Based on Dapper Drake, Ubuntu 6.06 LTS.
Was to be based on Edgy Eft, Ubuntu 6.10 or 7.04. include Domain Key signing. include my
6th Scrapped 2006-11 2007-10
mail admin or my catchall aliases admin.
Updated, based on Ubuntu 8.04 LTS Hardy Heron. Using Amazon EC2 as example. (Tested
7th Released 2008-04 2009-06
with 8.10 & 9.04 as well)
Based on Ubuntu 8.10 (intrepid), then tested with 9.04 (jaunty) & 9.10 (karmic) as well. Using
8th Released 2009-05 2009-11
official Ubuntu ec2 as examples.
Based Ubuntu 9.10 (karmic) using Canonical's cloud images. Added Roundcube webmail
9th (this) Release (candidate) 2009-11 2009-11
option.
10th Early draft 2009-11 2009-11 Next version. Early testing with Ubuntu 10.04 LTS (lucid) using Canonical's cloud images.
Further details av ailable in the change log and below in the introduction.
Return to top.
Introduction
Aim
2 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
This is a step by step howto guide to set up a mail server on a GNU / Linux system. It is easy to follow, but you end up with a powerfull secure mail server.
The server accepts unlimited domains and users, and all mail can be read via your favourite clients, or via web mail.
It is secure, traffic can encrypted and it will block virtually all spam and viruses.
Return to top.
Research
Dont take my word for it! Research others opinions and methods. Look at my references, look at Postfix.org's howtos, read the excellent books available (E.g. Kyle's or
Hildebrandt's), search the web or read the proper documentation.
If you refer to this howto in your own document, or find useful links, then let me know.
Donate
If you found this howto very useful, spread the word and help others?
If this howto was exceptionally useful why not donate me some beer money?
Or buy a postfix book using my amazon affiliate links further down?
Or buy a t-shirt from my t-shirt shop?
Otherwise send me a Thank You note? UK US EU
Return to top.
Software
MTA: Postfix
www.postfix.org
Simple, free and slick. Yup I am a sucker for anything that works easily. Postfix is powerfull, well established, but not too bloated, and is
security concious from the start.
Database: MySQL
www.mysql.com
Although I use Firebird for my application development, (or Hibernate/C-JDBC hybrids), MySQL is well supported for the sort of lookups
required in a mail server.
Anti-Spam: SpamAssassin
spamassassin.apache.org
Powerfull renowned spam fighting tool.
Anti-Virus: ClamAV
www.clamav.net
Free virus scanner that can be trusted and includes update daemon.
PostGrey
isg.ee.ethz.ch/tools/postgrey/
Postgrey is an excellent little script to stop 99% of all spam. All it does is on first contact for specific from-to combinations, tells the sender
server to try again in a little while, which most spammers cant afford to do. When proper servers try again after a few minutes it lets it
through.
Encryption: TLS
www.ietf.org/html.charters/tls-charter.html
Secure and trusted crypthography technology for encryption of SMTP traffic. Not too be confused with client encryption technology like GnuPG and S/MIME. They are
covered in the extend section. Formerly referenced as SSL.
3 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Please see software links appendix for further information about these software packages. In that section there is more links to documentation or forums, and viable
alternatives, downloadable packages, versions details etc.
Further software and tweaks are discussed in the extension section.
Also review other peoples opinion on these packages via my references.
Return to top.
Installation
Distrobution
Base Install
Repositories
Packages
Distribution Postfix
Ralf Hildebrandt, ...
This section is different for every distribution and for every version.
New £38.94
This howto is based on Ubuntu and its base of debian which uses apt-get. Therefor this section uses apt packages to its fullest.
For other installation method please refer to previous edition's software links and your own distribution for the documention for other
ways of installing. My 2nd edition(outdated) has instructions for Mandriva, general RPM and tarball compiling. Postfix Ge-Packt
Tobias
To follow the rest of this howto with another distrobution, you need to ensure all your packages have been installed with the same Wassermann
modules, E.g MySQL lookup on postfix and sasl, php in apache etc. New £15.04
I have set up mail servers using the 32bit and 64bit x86 platforms, and if all the packages are available then other, E.g. Mac platforms
should work too.
The Book of Postfix
Patrick Koetter
Base Install
With installing Ubuntu you have a choice of which base system to install. You may choose server or desktop image or very basic setups.
I will assume a server install, but it should not differ. The etymological
manual
Or if you have chosen an ec2 based server, you can: John Oswald
Ps. Please note that after a while Ill stop specifying the use of sudo, as it is up to yourselves if you use it or use a priviliged user, e.g.
root.
Linux Device
Drivers
Repositories Jonathan Corbet,
A...
For assistance with repositories, refer to this article on ubuntu's wiki. New £17.42
sudo vi /etc/apt/source.list
If main and universe already is listed, this is a quick find and replace to add the others all over:
As mentioned in the previous edition you also might want to find a repository closer to your server.
Packages
You need to install a whole bunch of packages. We will install them bit by bit. But first check your package sources are correctly pointing to main multiverse restricted
universe repositories of your current Ubuntu version.
sudo vi /etc/apt/sources.list
MySQL
4 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
This will prompt you for a root password. Choose someting wise and remember it! For purpose of this tutorial I will set it to rootPASSWORD
Postfix
Then we'll install postfix
This will prompt you to choose type of email server. Select internet site It will also suggest a server name. Correct this if needed.
SASL
Courier
will prompt you about webdirectories. You can say no to this. It will also warn you about the certificate location. Ignore it.
ClamAV
SquirrelMail
phpMyAdmin
ShoreW all
Amazon provides a firewall/ access control for its servers, so not always needed then, but nice to have. And in all others situations; a must have.
Extras
I also install a few other packages that I personally prefer. But nothing todo with the mail server.
Package status
To find out which packages you may have installed, you can use for example:
or
EC2 Bundle
My AMI flurdy-amis/ubuntu-mail-server-clean is based on Canonical's official Ubuntu with these basic mail server packages installed.
Return to top.
Configuration
Core/Simple
Firewall (Shorewall)
MTA (Postfix)
Database (MySQL)
Pop/IMAP (Courier)
5 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Advanced
Content Checks (amivisd-new)
Anti-Spam(SpamAssassin)
Anti-Virus (ClamAV)
Policy Check (PostGrey)
Secure
Authentication (SASL)
Encryption (TLS)
Webmail (SquirrelMail)
Administration (phpMyAdmin)
Firewall
Shorewall
Not essential for an EC2 image. It is essential for a normal server. UFW is bundled with recent Ubuntu distributions, but I still prefer Shorewall for servers.
Basically at first you want to only allow SSH. Then SMTP and IMAP from your IP only.
When you are confident that the mail server is secure, you can open SMTP to the world. If you prefer you can also open IMAP to the world, unless you have a very small
client IP range.
Later you may open web access to the webmail and admin gui. This you may also restrict to specific IPs.
SSH only
By default Shorewall in Ubuntu has an empty set up. You can find the default values for Shorewall in /usr/share/doc/shorwall-common/default-config. And examples in
/usr/share/doc/shorwall-common/examples. We will create a basic set up.
cp /usr/share/doc/shorewall-common/default-config/interfaces /etc/shorewall/
vi /etc/shorewall/interfaces
cp /usr/share/doc/shorewall-common/default-config/zones /etc/shorewall/
vi /etc/shorewall/zones
fw firewall
# loc ipv4
net ipv4
Then if needed to specify hosts you can do it in this file. E.g. If you wanto specify what is your home IP etc.
cp /usr/share/doc/shorewall-common/default-config/hosts /etc/shorewall/
vi /etc/shorewall/hosts
# loc eth0:192.168.0.0/24
cp /usr/share/doc/shorewall-common/default-config/policy /etc/shorewall/
vi /etc/shorewall/policy
cp /usr/share/doc/shorewall-common/default-config/routestopped /etc/shorewall/
vi /etc/shorewall/routestopped
You may put in a netmask of your ip range if you are more concerned.
Now for the main firewall rules. You can find predetermined macro rules for Shorewall in /usr/share/shorewall.
cp /usr/share/doc/shorewall-common/default-config/rules /etc/shorewall/
vi /etc/shorewall/rules
6 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
vi /etc/shorewall/rules
# Permit all ICMP traffic FROM the firewall TO the net zone
ACCEPT $FW net icmp
# mail lines
SMTP/ACCEPT net $FW
SMTPS/ACCEPT net $FW
Submission/ACCEPT net $FW
IMAP/ACCEPT net $FW
IMAPS/ACCEPT net $FW
#web
Web/ACCEPT net $FW
Firewall configuring is always risky business, as it is easy to lock yourself out. To test the setup syntax, run
shorewall check
Restart it with
/etc/init.d/shorewall restart
vi /etc/default/shorewall
startup=1
MTA
Postfix
You should put the name of your server in this file
sudo vi /etc/mailname
Could be something like smtp.domain.name, where domain name obviously is replaced with your domain name.
sudo vi /etc/postfix/main.cf
Debian and Ubuntu already puts in some sensible default values in this file. You may need to comment some of them out if we put the same in as well.
First specify the name of your server.
Next is the origin which is the domain appended to email from this machine, this can be your full servername, or domain name.
# myorigin=/etc/mailname
myorigin=example.com
Then decide what the greeting text will be. Enough info so it is useful, but not divelge everything to potential hackers.
Next you need to decide whether to send all outgoing mail via another SMTP server, or send them yourself. I send via my ISP's server, so it has to worry about the queing
etc. If you send it yourself then you are not reliant on 3rd party server. But you may risk more exposure and accidentally be blocked by spam blockers. And it is more work for
your server. Also many servers block dynamic dns hosts, so you may find your server gets rejected. However choose whichever you are comfortable with.
Next is network details. You will accept connection from anywhere, and you only trust this machine
inet_interfaces = all
mynetworks_style = host
7 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Next you can masquerade some outgoing addresses. Say your machine's name is mail.domain.com. You may not want outgoing mail to come from
[email protected], as you'd prefer [email protected]. You can also state which domain not to masquerade. E.g. if you use a dynamic dns service, then
your server address will be a subdomain. You can also specify which users not to masquerade.
local_recipient_maps =
mydestination =
Now we can specify some restrictions. Be carefull that each setting is on one line only.
Further restrictions:
Next we need to set some maps and lookups for the virtual domains.
You need to set up an alias file. This is only used locally, and not by your own mail domains.
8 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Next you need to set up the folder where the virtual mail will be stored. This may have already been done by the apt-get. And also create the user whom will own the folders.
Note: If using Amazon ec2 you may want to move the mail spool to /mnt or an EBS location. You will need to symlink correctly afterwards.
Return to top.
sudo vi /etc/postfix/mysql_mailbox.cf
user=mail
password=mailPASSWORD
dbname=maildb
table=users
select_field=maildir
where_field=id
hosts=127.0.0.1
additional_conditions = and enabled = 1
Create how to find the user id (this step I will eventualy remove)
sudo vi /etc/postfix/mysql_uid.cf
user=mail
password=mailPASSWORD
dbname=maildb
table=users
select_field=uid
where_field=id
hosts=127.0.0.1
Create how to find the group id. (this step I will eventualy remove)
sudo vi /etc/postfix/mysql_gid.cf
user=mail
password=mailPASSWORD
dbname=maildb
table=users
select_field=gid
where_field=id
hosts=127.0.0.1
sudo vi /etc/postfix/mysql_alias.cf
user=mail
password=mailPASSWORD
dbname=maildb
table=aliases
select_field=destination
where_field=mail
hosts=127.0.0.1
additional_conditions = and enabled = 1
sudo vi /etc/postfix/mysql_domains.cf
user=mail
password=mailPASSWORD
dbname=maildb
table=domains
select_field=domain
where_field=domain
hosts=127.0.0.1
additional_conditions = and enabled = 1
As you can see the 3 first are very similar, only the select_field changes. If you specify an ip in hosts, (as opposed to 'localhost') then it will communicate over tcp and not the
mysql socket. (chroot restriction). Actually you can avoid using separate uid and guid files as those details are the same for all, but I do anyway. Ps. remember to replace the
password with your chosen mail user password.
Return to top.
9 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Database
MySQL
Now we will need to create the tables for thos lookups just specified. First you need to create a user to use in MySQL for mail only. Then you need to create the database,
Take note of your chosen mail username and password. You will need the password you specified for root during MySQL package installation.
aliases
domains
users
We will create more later on for further extensions, but only these are relevant now.
Log in to mysql as the new mail user
The last few fields in the users table are not required, but useful if you extend later.
Next is to edit the MySQL's my.cnf file. In Ubuntu/debian this is created by default. In Mandrake I had to manually create a blank one in /etc. But we need to configure it, so:
sudo vi /etc/mysql/my.cnf
#skip-networking
10 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
However in todays file the default is to bind the address to localhost, which is fine.
bind-address = 127.0.0.1
It is very useful at the start to log any SQL calls that makes it to MySQL. So enable this line:
log = /var/log/mysql/mysql.log
Then in a few weeks comment it out when everything is working, as it slows mysql down
Restart MySQL to make sure its picking up the new settings.
Return to top.
syslog log management Download Free Mysql
Log management for logs and syslog Fast Free Guide: Scale-Out by Combining MySQL
and Simple, Free Download Now! with Your Existing Database
Pop/IMAP
Courier IMAP
Please refer to previous edition for more explanations. But below is the details of what you need to change.
sudo vi /etc/courier/authdaemonrc
authmodulelist="authmysql"
DEBUG_LOGIN=2
sudo vi /etc/courier/authmysqlrc
Changed user
MYSQL_USERNAME mail
MYSQL_PASSWORD mailPASSWORD
Changed database
MYSQL_DATABASE maildb
MYSQL_USER_TABLE users
MYSQL_CRYPT_PWFIELD crypt
# MYSQL_CLEAR_PWFIELD clear
Added maildir
MYSQL_MAILDIR_FIELD concat(home,'/',maildir)
MYSQL_WHERE_CLAUSE enabled=1
Lastly you can have a look at the imapd file, but no changes is needed.
vi /etc/courier/imapd
Return to top.
Summary
You now have a basic mail server!
Before continuing to the advanced and secure mail server you must ensure the basic setup works. This will save you from loads of pain further on.
It is very easy to make typos, miss tiny steps, unclear steps or simple actual errors in this howto.
11 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Return to top.
cd /etc/amavis/conf.d
less 05-domain_id
less 05-node_id
less 15-av_scanners
sudo vi 15-content_filter_mode
# #@bypass_virus_checks_maps = (
# \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
# @bypass_spam_checks_maps = (
# \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
Have a look at
less 20-debian_defaults
sudo vi 50-user
@local_domains_acl = qw(.);
$log_level = 2;
$syslog_priority = 'debug';
$sa_kill_level_deflt = 8.0; # triggers spam evasive actions
$final_spam_destiny = D_PASS;
# $final_spam_destiny = D_DISCARD;
We have not setup amavis to scan and pass along incomming email. Next we will setup postfix to talk to amavis.
vi /etc/postfix/master.cf
Append these lines to the end of the file (make sure they are not already present). (Note the -o lines have spaces in front of them.
12 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
-o disable_dns_lookups=yes
-o max_use=20
Also add the following two lines immediately below the "pickup" transport service:
-o content_filter=
-o receive_override_options=no_header_body_checks
sudo vi /etc/postfix/main.cf
content_filter = amavis:[127.0.0.1]:10024
This should be it to get amavis working. If emails are picked up by amavis and passed back to postfix then it looks okay. Next is to uncomment the anti virus and anti spam
lines in
sudo vi 15-content_filter_mode
@bypass_virus_checks_maps = (
\%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
@bypass_spam_checks_maps = (
\%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
sudo vi /etc/amavis/conf.d/50-user
@local_domains_acl = qw(.);
$log_level = 1;
$syslog_priority = 'info';
$sa_kill_level_deflt = 8.0; # triggers spam evasive actions
#$final_spam_destiny = D_PASS;
$final_spam_destiny = D_DISCARD;
Return to top.
Anti-Spam
SpamAssassin
The default config of spam assassin is okay. You could refer to previous edition for more configuration options.
You do need to tell SpamAssassin to start smapd on boot.
vi /etc/default/spamassassin
ENABLED=1
One configuration option you could tweak is to enable Bayes and auto learning.
vi /etc/spamassassin/local.rf
Return to top.
Anti Virus
ClamAV
ClamAV does not need setting up. Configuration files are in /etc/clamav, but they are automatically generated, so do not edit.
I read your email
13 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
By default freshclam, the daemon that updates the virus definition database, is run 24 times a day. That seems a little excessive, so I tend to set that to once a day.
It will also ask if you want it to be daemon (yes) and which server is closest to you.
If needed, the command below will redefine the configuration with a lot of questions. Not needed unless you need to configure.
Return to top.
Postgrey
The default config of postgrey is okay. However you need to tell Postfix to use it.
sudo vi /etc/postfix/main.cf
You can tweak whitelisting in /etc/postgrey. You can tweak postgrey configuration by tweaking /etc/default/postgrey. E.g. delay, auto whitelisting, or reject message.
POSTGREY_OPTS="--inet=10023 --max-age=365"
Return to top.
You know have an advanced mail server. You can use this, but Id recommend continuing. However this is a good point to test the set up so far and to insert
some data in the db.
Return to top.
Authentication
Normal email traffic between clients and servers are in open plain text. That includes passwords and content of emails. No, I will not fix your computer
SASL
SASL secures the actual authentication (login), by encoding the passwords so that it can not be easily intercepted. The rest of the emails are however in clear plain text.
This is a section I will revisit for the next edition! Meanwhile please refer to previous edition for more detail.
Encryption
TLS
Encrypting the traffic stops anyone else listening in on your email communications. And is very recommended. There are different types of communication to encrypt: The
data traffic between your email applications and the server when you read emails or when you send emails, and communication between other email servers and your server.
For the encryption of reading emails, it is Courier you need to configure. For sending, and beetwen server encryption it is Postfix.
TLS in Postfix
To encrypt you need certificates. Ubuntu creates some for you for which you can use while setting up the server. However before you go live, it is recommended to create
your own with your proper domain name etc. Please refer to previous edition for more detail.
vi /etc/postfix/main.cf
There are already some TLS settings in the default debian/ubuntu version of this file. I moved these to the end, for clarity, but that is up to you.
# TLS parameters
#smtp_use_tls = no
smtp_tls_security_level = may
#smtpd_use_tls=yes
smtpd_tls_security_level = may
#smtpd_tls_auth_only = no
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
#smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
14 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
vi /etc/postfix/master.cf
By default only the normal smtp service is enabled, which is fine. But I prefer to enable submission (port 587), so that clients can use it, and I can restrict them to TLS only.
Also enabled smtps service (port 465), for some compatebility with some older clients (outlook express etc).
TLS in Courier
Again Ubuntu has created a certificate for you, but if you want to create your own, especially for a properly named server, then do this.
cd /etc/courier
openssl req -x509 -newkey rsa:1024 -keyout imapd.pem \
-out imapd.pem -nodes -days 999
vi /etc/courier/imapd-ssl
TLS_CERTFILE=/etc/courier/imapd.pem
IMAP_TLS_REQUIRED=1
For maximum compatability it is not wise to restrict to TLS only for the traffic between servers. As this means not all valid emails sent by others can reach your server.
However enabling them the option to encrypt is a good idea.
Be aware that the emails are not encrypted on your machine, nor on the server. For this type of client encryption, please refer to previous edition for more on GnuPG.
In some situations SASL and TLS do not play well together. Those situations are in combinations of storing encrypted passwords, using MD5 authentication over encrypted
traffic. I recommend, insisting on TLS traffic with your authenticating clients, which then negates the need for SASL.
You know have an advanced secure mail server. Now is another good point to test the set up so far and to insert some data in the db.
Return to top.
Webmail
Using among others the https://help.ubuntu.com/community/Squirrelmail as an updated reference.
Alternative
If you prefer the prettier Roundcube, but less powerfull (at the moment), the follow the Roundcube section in the extention section.
15 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
You may accept the default apache configuration where squirrelmail is folder in all sites. But I prefer virtual hosting. But you dont need to do these next steps.
sudo vi /etc/apache2/sites-available/squirrelmail
DocumentRoot /usr/share/squirrelmail
ServerName webmail.example.com
If you have apache SSL enabled in apache, then you can also uncomment the mod_rewrite section for further security.
Reload apache to activate changes. First test if ok.
sudo apache2ctl -t
You can now go toyourdomain.com/squirrelmail/ or mail.yourdomain.com if you chose virtual host. This should show a squirrel mail page. Log in wont work yet though.
sudo squirrelmail-configure
Initially change nothing. You can customize more afterwards. You can browse, and exit sub menues by typing R.
Type 2 to edit server settings. Type A to edit IMAP settings.
Type 8 to edit server software. Enter courier.
courier
Now they say using TLS over localhost is a waste of time. But I do anyway. Type 7 to edit secure IMAP. Type
to enable it.
Type 5 to edit IMAP port. Enter
993
Please refer to previous edition for more detail. E.g. creating address books and user preferences.
Return to top.
Administration
Enable web access
You may need to enable web access in the firewall. Check the firewall configuration if this neccessary.
You need to copy a phpMyAdmin configuration to apache.
You may choose to restrict phpMyAdmin to a spefic virtual host. If so you need to, edit
sudo vi /etc/apache2/sites-available/phpmyadmin
and comment out the alias. And insert the alias into a virtual host configuration. For this example we are not.
Reload apache to activate changes. First test if ok.
sudo apache2ctl -t
16 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
You can now go to http://yourdomain.com/phpmyadmin/, and login with the mail user. You can use it as it is, but I recommend securing it a bit more.
One simple way is adding apache's .htaccess login requirement.
Further restrictions can be restricting to a specific virtual host. Or renaming the folder. Purely ubfuscating, but simple.
Or using the example in the webmail section, and adding SSL requirement to the connection. Or disabel mysql root's access via phpMyAdmin.
Please refer to previous edition for example on htaccess, and mysql user restriction.
You know have a finished mail server. This is as far as the main guide goes. Hope it was clear enough to follow.
Now it is time to insert data, and to test how it works.
Feel free to extend it with my suggestions further down.
Return to top.
Data
Then some default aliases. Some people say these are not needed, but I'd include them.
17 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
There is also a "Karl" user, but he does want all mail forwarded to an external account.
So what does each of these lines actually do? Well the domains are pretty straight forward.
The users are as well, it requires four fields. ID is the email address of the user, and also its username when loggin in, described later on. NAME is optional description of the
user. MAILDIR is the name of the folder inside /var/spool/mail/virtual. It must end in a /, otherwise it wont be used as a unix maildir format. CRYPT is the encrypted text
password to use.
The alises are the interesting part. Lets start from a top down view to see how emails get delivered:
Say an email arrives addressed to "[email protected]".
Any mail arriving for "[email protected]" or "[email protected]", gets forward to an external address of "[email protected]". So forwarding is simple. I tend to use a
subdomain for all my friends addresses as easily I forget what their real addresses are, and I use different email clients all the time.
I also added the required aliases of postmaster and abuse to blobber.org and whopper.nu. The catchall for lala.com means they are not required for that domain.
Another useful alias to add is root, as often you get admin mail from e.g cron jobs within those domains etc. Other often used aliases are info, sysadmin, support, sales,
webmaster, mail, contact and all. But they are also honeypots for spam, so just include the ones you think you will need.
Adding template
So to add a new domain to the system, You do this, replacing the italics with relevant data:
Return to top.
Common SQL
A selection of useful sql statements, if you are not using an admin/manager program to maintain your email domains and users.
Find domains without a catchall
18 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Find all aliases for a certain domains, checking if enabled for both domain and alias
select *
from domains d
join aliases a
on a.mail like concat( '%','@',d.domain)
and a.enabled = 1
where d.enabled = 1
and d.domain like '%foobar%'
order by d.domain,a.mail
Return to top.
Test
Common problems
Test strategy
Tail, tail and tail again
Switch off services
Switch debug on
Telnet is your friend
Can postfix receive?
Can postfix send?
Can courier read?
Common problems
Missed a step
If you mistakenly or intentially skipped past sections, you may have missed an important step in your configuration, which my guide pressumes you have followed.
Typo
99% of all problems is spelling errors or typos you entered while following this guide. Sorry, but it just happens. Often it can be trivial, such as a space at the end of
the configuration line which was not expected etc. Or not understanding my example where it is a multi line entry.
Typo by me
Yes, I make a lot of mistakes. Nothing wrong in that, but I hope I have corrected most over time. Any new sections are however at risk... :)
Distrobution/version differences
If you run a different version or even distrobution to this guide, then some things will be different. Small issues, such as default values and significant things such as
path differences etc. Some sections in this guide are not always thouroughly tested with every new release of Ubuntu, but these differences gets pointed out by
people for me.
Return to top.
19 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Test strategy
What steps to think of when testing.
Test in order
As part of the isolating the problem rule, you most of the time test in order, and test each section thus isolating the problem. This would then quickly isolate the problem when
e.g. such as above issues of reading emails via the webmail. This would be in order:
/var/log/system.log
/var/log/mail.log
/var/log/mysql.log
/var/log/apache2/access.log
In one window:
tail -f /var/log/mail.log
tail -f /var/log/mysql.log
previous edition 2
The previous editions has detail on switching services off untill time to test them.
It also details locking down your server from spammers untill finished testing.
Return to top.
Switch debug on
Shorewall
You can also switch on more messages for when the firewall is rejecting connections. Add info to all REJECT, BOUNCE and DROP policies.
sudo vi /etc/shorewall/policy
such as:
MySQL
There is no point in tailing the mysql log if query debugging is not turned one.
By default it is not. However in this guide I do switch it on, in case that was missed switch it on now:
sudo vi /etc/mysql/my.cnf
20 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
log = /var/log/mysql/mysql.log
Courier
As mentioned in the setup , switching on debugging for Courier is easy:
sudo vi /etc/courier/authdaemonrc
DEBUG_LOGIN=2
Amavis
You can also debug amavis:
sudo vi /etc/amavis/conf.d/50-user
$log_level = 2;
Return to top.
1. First you test it on the server to exclude firewall and network issues.
2. Then you test it from another machine to simulate an actual other mail server.
3. Once these are working you can use proper email clients, however 99% I just use mutt locally when I need to test if a server is working.
Return to top.
Try this locally on the server first, then try from another machine once it is working locally.
Lets try and send a message to [email protected] (replace with your own user in this setup, or use postmaster@localhost) from [email protected] (again replace with
a real email address you use that is not associated with this server.)
telnet localhost 25
# Open the hand shake with ehlo and the server name you are connecting from...
# Change mail.example.com to something valid eg your servername
EHLO mail.example.com
# The mail server will then dump out some details about its capabilities, e.g.
>250-mail.flurdy.net
>250-PIPELINING
>....
>....
# then say who is the sender of this email
MAIL FROM: <[email protected]>
> 250 Ok
# then say who the mail is for
RCPT TO: <[email protected]>
> 250 Ok
# then enter the keyword data
data
> 354 End data with <CR><LF>.<CR><LF></LF></CR></LF></CR>
# enter message bodyand end with a line with only a full stop.
blah blah blah
more blah
.
> 250 Ok; queued as QWKJDKASAS
# end the connection with
quit
> 221 BYE
If while you were doing this you were tailing the /var/log/mail.log you would see some activities and if any errors occured. (You should probably get some complaints about
missing headers as we skipped most...)
If while you were doing this you were tailing the /var/log/mysql.log as well you really should have seen some activity otherwise you have a problem.
If you see any errors (or worse no activity) in these log files, this is what you need to fix! For common problems and solutions check the previous edition.
However if no errors popped up, and the folder /var/mail/virtual/xandros now exists then your server can receive emails!
Return to top.
21 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
You need to make sure you can first receive emails as above
The services MySQL and Postfix are running.
Basically you just tested that above, but we need double check if it can send out to other servers. Again we will first test locally, which should work, then remotely which
introduces many possible problems.
telnet localhost 25
# Open the hand shake with ehlo and the server name you are connecting from...
# This time it has to be the name of your server
EHLO mail.example.org
# The mail server will then dump out some details about its capabilities, e.g.
>250-mail.flurdy.net
>250-PIPELINING
>....
>....
# then say who is the sender of this email, which is a local user
MAIL FROM: <[email protected]>
> 250 Ok
# then say who the mail is for which is an external address e.g. gmail etc.
RCPT TO: <[email protected]>
> 250 Ok
# then enter the keyword data
data
> 354 End data with <CR><LF>.<CR><LF></LF></CR></LF></CR>
# enter message bodyand end with a line with only a full stop.
blah blah blah
more blah
.
> 250 Ok; queued as QWKJDKASAS
# end the connection with
quit
> 221 BYE
We have to assume receiving works above so no need to tail mysql's logs. However if any rejection errors occured in the mail.log then you have an error.
However if no errors occured and you see in the log something like this:
You need to make sure you can first receive emails as above
You need to make sure you can send emails as above
You need to make sure you have received an email and the folder /var/mail/virtual/xandros exists
The services MySQL, courier-authdaemon and courier-imap are running.
There is not too much you can test via telnet for courier. But you can check if it is up and you can connect to it.
The rest you would have to test via a proper email IMAP client.
Return to top.
Intialize
Brief hints if you receive a ready setup machine (or EC2 AMI), and what then to check and to customize it to your setup.
Stop services
Restrict firewall
Change passwords
Check configurations
Set machine name
Certificates
Start and test services
Insert data
Reload postfix
Open firewall
Test
Stop services
First stop services so they wont accidentally do something.
22 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Restrict firewall
Check what the firewall rules are.
vi /etc/shorewall/rules
Change passwords
Next the passwords needs to be changed. For both the system and mysql.
System passwords
Check which users are defined on the system.
cat /etc/passwd
Apart from all the system ones, there should probably be none (if EC2 AMI) or just your user if it is a standard Ubuntu install. If there are some users, you need to change their
passwords.
SSH Access
Next we check whom got SSH access. If there was any users defined, check their home folders for ssh keys.
cat /home/username/.ssh/auth*
Remove any you do not expect to be there. Next check if and which specific users has been defined for SSH access in
vi /etc/ssh/sshd
MySQL passwords
First you need to change the root mysql user. If none has been set do this
Otherwise do this and you will be prompted for the old password
Then the default mail user as well. If you know the old password
mysql -u root -p
You may need to revisit the top of MySQL section to re-grant the mail use rights on the database.
If you do not know the old root password, you have to restart mysql without grant rights. Google it... :)
Update postfix mysql configuration files with the new password.
sudo vi /etc/postfix/mysql*
password=apassword
sudo vi /etc/courier/authmysqlrc
MYSQL_PASSWORD apassword
Check configurations
You should scan the postfix, courier, etc. configurations to check if they match what you expect.
sudo vi /etc/mailname
sudo vi /etc/postfix/main.cf
23 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
myorigin=yourdomain.com
hostname
All though this does not have to be the same as your postfix mail server name. You may want to speficiy some hosts in hosts file as well,
sudo vi /etc/hosts
Certificates
You could go along with the generated certificates (if they are there, default for Ubuntu). Or if you could create new ones with the correct machine name in them. Especially if
this a mail server used by many, and authenticiy is important. Follow the TLS certificate instructions for Postfix and Courier.
Insert data
Insert your mail domains, aliases and users using the data section.
Some times there are test data already in the database. Remove them. E.g.;
Open firewall
Then open up the firewall, follow the world access bit in the firewall configuration. Voila. Up and running. Well we hope.
Return to top.
Extend
Please refer to previous edition for how and why you can extend this mail server.
By now you should have a fully working system. No point extending and complicating it untill then. What next? There are many ways to
extend the server, to create your own powerfull customized version.
Spam reporting
White/Black lists
Relocation notice
Pop-before-SMTP
Admin Software
Auto Reply
Block Addresses
Throttle Output
Mail Lists
Roundcube webmail
Sugestions?
Some of these sections can be brief as they are not core to this howto.
24 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Now presuming the other backup mx is a postfix server identical to this, or you are backuing up someone else's server;
Go into mysql and create this tables:
CREATE TABLE `backups` (
`pkid` smallint(6) NOT NULL auto_increment,
`domain` varchar(128) NOT NULL default '',
`transport` varchar(128) NOT NULL default ':[]',
`enabled` smallint(6) NOT NULL default '1',
PRIMARY KEY (`pkid`),
UNIQUE KEY `domain` (`domain`)
);
Then still on the backup server, edit main.cf and add these:
relay_domains = mysql:/etc/postfix/mysql_backups.cf
transport_maps = mysql:/etc/postfix/mysql_transport.cf
You may choose to have this as the last line in the file, as you may use small cron jobs to modify this ip address, if you don't have a permanent static address. It should
contain your IP addres, hence if you do not have a very static IP address, that you need to automatic editing if the postfix file.
proxy_interfaces = 1.2.3.4
user=mail
password=apassword
dbname=maildb
table=backups
select_field=domain
where_field=domain
hosts=127.0.0.1
additional_conditions = and enabled = 1
user=mail
password=apassword
dbname=maildb
table=backups
select_field=transport
where_field=domain
hosts=127.0.0.1
additional_conditions = and enabled = 1
You noticed I added a transport lookup. This is a field in both the domain and the backup tables. In domains it is used to determine how to deliver the email, ie either virtual
(correct) or local (not used in this howto). When backing up servers, your also need to specify in the transport field how to connect to the correct servers.
Say you are backiup for a friends server, mail.friend.com, for the domains of friend1.com and friend2.com. So you should insert this into your backup table.
The :[] tells to connect directly to this server, not doing any more look ups for valid MX servers.
This shouls now work fine. Further tweaking of the queue values, review these and modify as appropiate. Shorter warning times are good for the sender, so that they realise
the email has not arrived yet, but may also be annoying. Tradeoffs.. Look in the first main.cf configurations for ways to do so.
Return to top.
25 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
You may combine a full backup with a intermediate update of what has changed recently only.
Return to top.
SPF configuration
The pobox site has some nice SPF generation tools to setup your SPF configuration. Probably best to use theirs.
But the way I have my setup, is generally one domain with detailed SPF, then all other domains just with an SPF alias to it. e.g:
Main domain DNS TXT field:
I list the mail servers and websites associated with this domain (the a and mx bit).
I then specifically list the name of a server I may send mail from applications automatically using addresses within this domain.
As you can see I also use Google Apps with this domain, thus tell SPF to also allow all mail servers associated with google mail.
Then for most of the other domains I would use this DNS TXT field:
I list the mail servers and websites associated with this domain
Then I tell SPF to also allow all mail servers associated with my main domain (example.com).
SPF problem
It is worth noting about SPF, that you should leave the decision to whether to reject or allow the email to the mail servers. Therefor using -all instead of ~all is not a good
choice. Leave it to the SPAM scoring by the receiving server, like SpamAssasin does it. You then minimise the risk of false positives.
One of the reason I do discourage -all use, is that SPF has a distinct problem:
It does not like email forwarding or use of backup MX!
Consider this: Your address of [email protected] sends a joke email to a few friends. One of these is [email protected].
Trixie's email address is actually an alias and forwards the email to her private webmail account on hotmailnot.com.
Now if your domain, hoopa.com, have a strict SPF set up, which only allows emails to be sent by its mail server. And you/the mail admin has added -all to the SPF, which tells
other server to reject emails not from your server. This you think makes sense, spammers can not use your domain for spoof emails.
So what happens: bellbell.org receives the email from lulu, and possible checks the SPF, which is OK, and forwards it on to hotmailnot.com.
However if hotmailnot.com also checks SPF, it will receive the email from bellbell.org, check the SPF to see bellbell.org's mail server is allowed to send emails on behalf
hoopa.com. SPF will say No!, and with the -all, hotmailnot.com email server will reject the email!
2nd scenario if lulu email trixie directly at hotmailnot.com, but hotmailnot.com main mail server was down, and email was sent to the backup mx server. When the main server
came online again, and the backup spooled the email back to it, the SPF would again fail as the hoopa.com's SPF would not mention hotmailnot.com backup mx as an
allowed mail server.
Solution:
Of course you can not list all possible forwarding / backup mx email server that your domain's users might at some point email!
I simple just use the ~all option. Which simple say it is not the expected server, but probably ok.
And if this is added to a scoring by the receiver, then the accumulated spam score might be enough to reject dodgy emails.
Return to top.
Spam reporting
todo
Reporting spam to Pyzor, Razor and SpamCop, for collaboration in spam fighting.
More detail on SpamCop is here.
pyzor.sourceforge.net
razor.sourceforge.net
Return to top.
White/Black Lists
todo
You can implement white and black lists to explicitly allow or block domains and users.
26 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
You have already visited the option of a blackhole list of known open relays in the postfix configuration.
You can implement further lists inside Postfix or SpamAssassin. Amavisd-new already has a few well known white/black listed items in its config files. SpamAssissin also as a
feture to automaticly learn white lists.
Return to top.
To import GnuPG into Evolution; in your settings/preferences edit your account settings and add you private key under the security tab. The private key is found via listing the
GnuPG keys as above, then it is the 8 characters after the "sub 1024g/" bit of you key.
To use GnuPG with Thunderbird you need to install EnigMail.
S/MIME is another way to encrypt and/or sign messages. You can create you own certificate or use known organizations like Thawte. (Thawte was originally set up by the
Ubuntu founder)
Return to top.
Relocation notice
If people change addresses, a bounced message stating so if people send email to the old address is quite useful. To implement this in postfix, frst create a lookup table in
the database.
relocated_maps = mysql:/etc/postfix/mysql_relocated.cf
user=mail
password=apassword
dbname=maildb
table=relocated
select_field=newadr
where_field=oldadr
hosts=127.0.0.1
If anyone sends an email to [email protected], they will get a message back stating he has changed address to [email protected].
Return to top.
Pop-before-SMTP
If SASL didn't work, or you are using clients which dont support it, the Pop-Before-SMTP is an easy way around that issue, so that people externally can still securly send
mail via your server.
Refer to my 2nd edition on Pop-before-SMTP setup.
Return to top.
Admin software
todo
Trying out a few admin software might make you life easier, if phpMyAdmin gets to crude. Quick search
More to come later.
Return to top.
Auto Reply
todo
Postfix have now features to auto reply to an email, while still delivering it to its alias.
Return to top.
27 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Block Addresses
If you use catch alls, which are useful for some domains, then eventually some addresses will be target for spam. You can then either stop the catch all, or stop indivdual
addresses.
By implementing a lookup and adding this restriction to smtpd_recipient_restrictions accomplises this.
check_recipient_access mysql:/etc/postfix/mysql_block_recip.cf,
Beware of the order is important here, if any options says ok before check_recipient_access it will ignore it.
Next create mysql_block_recip.cf to lookup addresses. Either create a another table, or add a blocked field to aliases table.
Return to top.
Throttle Output
todo
For some users with restrictions on bandwidth, you may wish to control how much mail is sendt out. Postfix has long refused to implement these features, out of ideolocial
beliefs that mail servers should not be restricted. However there are some ways around this. More to come later.
Return to top.
Mail Lists
Rich Brown has written a howto on adding Mailman, a mail list program, to my howto. Click here to read it.
Do note it is not part of my howto, so do not contact me regarding it. And although I think it is fine, I can't guarantee it will work.
If you do need assistance or need to talk about it, contact Rich via his howto or use the forums for this howto.
If you want a simple mailling list, it can be implemented by simply seperating aliases in the destination field in the aliases table with a comma.
Return to top.
I have for various reasons integrated some Google Apps hosted domains into my mail server. And you can still have good control over the addresses by using your server
with Google Apps.
More information on Google Apps.
Why
How
Options
The easiest and simples solution is not to have a domain MXed to your server, and simply alias email to those domains. eg All email to joeblogs.co.uk hosted on your server
are forwarded to joeblogs.com hosted with google.
You may set up your own server to simple be a mail server backup (mx) for a domain hosted with google. If you are the first priority in the MX details of the DNS, you still have
some control, but not all will obey the priority listing. E.g. spammers, but some valid senders as well.
However the one I use and the option where you are most in control is to keep you server as the only MX server in the DNS. And only forward certain aliases onto Google
after all your servers checks. Other aliases and user can just use your mail server if you prefer. I will explain how to do this in the next steps.
DNS
You only put your mail server as the mx for the domain in question. Google will complain about this, as it will not be able to verify that email is setup correctly. Ignore this as it
will still accept emails.
MySQL tables
You setup you aliases as normal. However you domain table needs tweaking. This is because otherwise your server will just forward the email to itself. You can actually
specify aliases in the domain table.
Example: Your domain is bloggs.com. Joe wants to use gmail. Mary does not.
to be done
to be done
Issues
There are some items you should consider when integrating Google Apps.
Privacy
28 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
First there is the privacy issue. This is the same as if you were using Google Apps only or GMail. Google can and will read your email. However probably not a person, but
they will use it for commercial reasons, E.g. showing relevant ads. Some people really hate this part and refuse to use Google's mail products. However I trust them a little bit,
and do use it.
Spam
If you forward spam, then consider your own servers reputation. Should be okay though.
SPF
If you use SPF for your domain, consider that both your server and google will receive and send mail on behalf of that domin.
Google internally
Be aware Google think they host you domain. So if others inside google, or using google hosted apps or GMail, if they email you, the email may not go via your email server,
but directly to the Google Apps for your domain. That could be an issue if not all aliases you have use Google Apps. This needs to be tested more though. Especially as it
may only be an issue if Google's servers are part of you domains MXs.
Return to top.
It will ask you if you want to configure its database access, answer yes, then select mysql. Then it will ask for the root mysql uses password, which it will create a roundcube
mysql user and ask for its desired password.
This will create a symblink in /etc/apache2/conf.d/ to /etc/roundcube/apache.conf. Edit this file.
sudo vi /etc/roundcube/apache.conf
Depending on your setup you may want to move those Alias commands at the top to your virtual hosts configuration, or for this example enable them here for all hosts.
sudo vi /etc/roundcube/main.inc.php
Modify these lines for added security and ease of log in:
$rcmail_config['default_host'] = 'ssl://localhost:993';
$rcmail_config['smtp_server'] = 'ssl://localhost';
$rcmail_config['smtp_port'] = 465;
$rcmail_config['create_default_folders'] = TRUE;
There are other tweaks and security features you can enable such as:
$rcmail_config['sendmail_delay'] = 1;
Then go to your roundcube installation depending where and how you modified those Aliases, e.g. at http://mail.example.com/roundcube.
That should be it
You can obviously modify and tweak further. One thing that may be usefull is to have the Roundcube Apache Alias on different virtual hosts, and configure username_domain
in main.inc.php to append different email addresses, or configure the default_host to different mail server depending on virtual host... More details on the Roundcube Wiki.
Return to top.
Suggestions?
If you have any suggestions to other ways of extending a postfix server, then fire off a mail to me via the contact form further down.
(Or rather, Id prefer that you write down the extension, and let me know the link! :))
Return to top.
29 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Impressions
ec2 introduction, tips and hwotos
Using EC2 with this howto
Amazon EC2 Images: AMIs
EC2 Links
Impressions
Easy to use. Anyone can use, not just big companies. Very useful. Tools are command line but simple. Firefox
extensions work well. Recommended.
I find it very usefull. Basically it is a colo hosting environment. Some may use it as for Saas, ie single scalable
application in the cloud, but I use it as a hosting environment for complete servers.
Ubuntu
AMI Description S3 Name Extended from
version
Base install: Canonical's Official Ubuntu 9.10 canonical-cloud-us/ubuntu-karmic-9.10-i386-server-
ami-1515f67c 9.10 Karmic
Karmic 32bit US 20091027.1
Base install: Alestic Ubuntu 8.04 LTS Hardy 32bit 8.04 LTS
ami-c4f615ad alestic/ubuntu-8.04-hardy-base-20091011
US Hardy
Base install: Alestic Ubuntu 8.04 LTS Hardy 32bit 8.04 LTS
ami-ce44a1a7 alestic/ubuntu-8.04-hardy-base-20080430
US Hardy
ami-4132d428 (Clean
ami-eb39df82 Just mysql, postfix and courier configured flurdy-amis/ubuntu-mail-server-basic-20090604-1 8.10 Intrepid
Canonical)
8.04 LTS
ami-9941a4f0 Including anti spam and anti virus flurdy-amis/ubuntu-mail-server-spam-080504-1 ami-8541a4ec (Simple)
Hardy
30 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
8.04 LTS
ami-275fba4e With webmail and admin enabled flurdy-amis/ubuntu-mail-server-webmail-080527-1 ami-395fba50 (Secure)
Hardy
8.04 LTS
ami-xxx With back up mx flurdy-amis/ubuntu-mail-server-backup-xxx ami-275fba4e (Webmail)
Hardy
8.04 LTS
ami-xxx With back up mx only flurdy-amis/ubuntu-mail-server-backup-only-xxx ami-395fba50 (Secure)
Hardy
If you have a comment or question about the ec2 images, please discuss it in the forums? If you notice a security problem, or I have not cleaned the images properly please
let me know?
EC2 Links
Return to top.
Appendix
About author
Contact
Why
References
Software Links
Difference between Ubuntu versions
Download
Todo
Change Log
About author
Ivar Abrahamsen, an IT Senior Consultant from Norway. Specialising in developing and integrating middleware application systems. Mainly open source and Java based
technology stack. Recently moved back to Oslo, Norway after 15 years in Manchester.
Return to top.
Contact
Remember I have stood on the shoulders of giants. I just ended up with a system that worked for me, and decided to document its evolution.
Before contacting, have you?:
Forums
Use the Ubuntu forums! :)
31 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
And even better if it something you may know how to solve, please let people know.
And especially, if you post a problem, then solve it, let people know what the solution was! (and not just that you solved it...)
I am rubbish in replying to emails, and the forums are read and answered by people whom know a lot more about Postfix than me.
Questions sent to me directly may not be answered for a while or at all unfortunetly.
Return to top.
Return to top.
Why
Why your own mail server
Main reason: Because you can.
Other good reasons: Basically it leaves you in complete control, to expand, customize and tweak your mail server to your needs. You are
not dependant on 3rd party providers, limited by their technology contraints or your budgets. With your own mail server you can add as
many aliases, users and domain as you'd like, be as restrictive or open about security, virus, spam, file sizes etc as you prefer. And is it is
well known, frequently updated, open source application stack, you can also trust the software you use.
References
Postfix howtos
Kyle's book
John Locke on TechRepublic
Hildebrandt's book
Hildebrandt's website
List-Petersen
Genco Yilmaz
Christop Haas
Nenzel & Peet
Peters
32 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Matthews
Stepanov
Andy "Besy"
Meta Consultancy
New references
Postfix TLS
Postfix main.cf doc
saslauthd
Bypassing amavisd
Ubuntu Help: Squirrelmail
Return to top.
Software Links
Please refer to the previous edition for a list of urls and suiteable downloads. However most are unneccessary with decent package manager.
Download
Please refer to the previous edition for a complete lists of downloads that are available.
Change log
Brief list of latest changes.
2009-12-16: Expanded test section with text from older editions and new babble.
2009-11-25: Bumped to edition 9!
And added Roundcube as webmail client.
2009-11-11: Updated to work with 9.10 Karmic Koala.
2009-06-04: made basic server image available on ec2. based canonical's official ec2 ami.
2009-06-02: made clean server image available on ec2. based canonical's official ec2 ami.
2009-05-29: changed contact section.
2009-05-29: started 8th edition
Used to refer to all changes, but got too long. A previous edition contains such a list.
Return to top.
Todo
Populate some of the: Refer to previous edition...
Spell check!
Remove uid and guid
Copy across test sections from earlier
Merge test sections
Create backup mx AMI
FAQ
There is not yet an extensive FAQ.
But please, most of the frequent questions have been asked and answered in the forums.
Most are also unneccessary as following the test section will have solved them.
Some question that frequently get sent to me, which first of all should have been asked in the forums and has been answered there many times, which then I tend to ignore
are:
33 de 34 19/01/2010 11:40
How to set up a mail server on a GNU / Linux system http://flurdy.com/docs/postfix/
Answers:
Have they received an email?
If not they you can not log into squirrelmail as the email folders will not yet exist. When receiving their first email, postfix will create all the neccessary folders. If
it does not your postfix setup is broken.
There is a program that creates the folders for you.
I do not recommend it, as basically your postfix setup is broken if no folders are created, and you better fix it instead.
Return to top.
34 de 34 19/01/2010 11:40