Mail Server Installation on Ubuntu

As a beginner to linux it took about almost 10 days of goggling for me for proper installation of mail server and fixing necessary problems. Before you start this you should look into these posts Some Important Linux commands for Newbies and Setup LAMP With Ubuntu In 10 Minutes. We will setup Postfix (Mail Transfer Agent MTA), Dovecot (IMAP/POP3 Server), SASL Authentication with TLS (Authenticate before sending mail outside network in Outlook) and Squirrel Mail (Popular Web based Email).

Note: If you install Postfix/Dovecot mail server you will ONLY be able to send mail within your network. You can only send mail externally if you install SASL authentication with TLS. As otherwise you get nasty “Relay Access Denied” error.

Install Postfix MTA (Mail Transfer Agent)

apt-get install postfix postfix-tls  libsasl2-2 sasl2-bin libsasl2-modules popa3d

During installation, postfix will ask for few questions like name of server and answer those questions by entering your domain name and select Internet site for postfix.

Postfix configuration file is located at:/etc/postfix/main.cf. You can edit this file using popular text editor nano /etc/postfix/main.cf
Start or Restart Postfix Server:

/etc/init.d/postfix restart
/etc/init.d/postfix stop
/etc/init.d/postfix start

Install Dovecot

apt-get install dovecot-imapd dovecot-pop3d dovecot-common

Dovecot configuration file is located at: /etc/dovecot/dovecot.conf

Before we proceed we need to make some changes with dovecot configuration file. Double check the following entries in the file if the values are entered properly.

nano /etc/dovecot/dovecot.conf 

# specify protocols = imap imaps pop3 pop3s
protocols = pop3 imap
# uncomment this and change to no. 
disable_plaintext_auth = no 
pop3_uidl_format = %08Xu%08Xv

Now, create a user to test our pop3 mail with outlook:

adduser <user_name>

Restart Dovecot:

/etc/init.d/dovecot restart

Configure SASL Authentication with TLS
SASL Configuration + TLS (Simple authentication security layer with transport layer security) used mainly to authenticate users before sending email to external server, thus restricting relay access. If your relay server is kept open, then spammers could use your mail server to send spam. It is very essential to protect your mail server from misuse.

Let us set up SMTP authentication for our users with postfix and dovecot.

Edit the postfix configuration file /etc/postfix/main.cf and enter the few lines to enable authentication of our users

smtpd_sasl_auth_enable = yes 
smtpd_sasl_local_domain = yourdomain.com
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination 
smtpd_sasl_security_options = noanonymous

On the Dovecot side you also need to specify the dovecot authentication daemon socket. In this case we specify an absolute pathname. Refer to this postfix manual here

Edit /etc/dovecot/dovecot.conf

Look for the line that starts with auth default, before that insert the lines below.

auth default {
mechanisms = plain login
passdb pam {
}
userdb passwd {
}
socket listen {
client {
path = /var/spool/postfix/private/auth
mode = 0660
user = postfix
group = postfix
}
}
}

Now, rename previous auth default to auth default2. If you dont rename this then dovecot server will give you error like multiple instances of auth default.

Now restart all the components of mail server.

/etc/init.d/saslauthd restart
/etc/init.d/postfix restart
/etc/init.d/dovecot restart

NOTE:
1. If you dont enable My server requires authentication in outlook you cannot send emails to external recipients and you get relay access denied error.
2. Do not use root login to login to your mail server.
3. Dont forget to create a new user before you authenticate using outlook.

Installing Squirrel Web Mail
Squirrel mail is one of the most popular web based email with very friendly interface. Squirrel mail works without mysql database very easy to install and configure under apache2.

apt-get install squirrelmail

Squirrelmail configuration file is located in: /etc/squirrelmail/ folder. By default all settings are preloaded.

# Run squirrelmail configuration utility as ROOT
/usr/sbin/squirrelmail-configure

Now we want to setup to run under apache. Edit apache configuration file /etc/apache2/apache2.conf and insert the following line:

Include /etc/squirrelmail/apache.conf

Thats it. Your webmail is ready !!! Point your browser to: http://yourdomain/squirrelmail

About Zakir Hyder

This entry was written by .

02. February 2012 by Zakir Hyder
Categories: Linux, Server Management | Tags: , , , , , , , , | Comments

Comments

  1. […] Mail Server Installation on Ubuntu As a beginner to linux it took about almost 10 days of goggling for me for proper installation of mail server and fixing necessary problems. Before you start this you should look into these post Some Important Linux commands for Newbies and Setup LAMP With Ubuntu In 10 Minutes. We will setup Postfix (Mail Transfer […] […]

  2. Simbarashe says:

    Zakir Hyder,thank you man for the Tutorial,im trying to come up with my own internal Mailserver,which can only relay mails within my organisation.I have a basic understanding of Linux.Could you assist me on how to it?Do we have to setup DNS server etc before we install postfix/dovecot or what you said is what only required?Please assist me,sorry to be nuisance.

    Thank you in advance

  3. Zakir Hyder says:

    Hi Sim,
    Yes you have to setup DNS before you set up mail server. For Squirrel Web Mail you have to install AMP(Apache+MySql+PHP). But if you want Squirrel Web Mail or any other web based interface then just DNS setup will be enough. Follow this tutorial http://blog.jambura.com/2011/12/18/ubuntu-linux-setup-and-configure-a-domain-name-server-using-bind/

  4. penreturns says:

    root@vps:/home/rc# apt-get install postfix postfix-tls libsasl2-2 sasl2-bin libsasl2-modules popa3d
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package postfix-tls

  5. Zakir Hyder says:

    I just checked the command on Ubuntu 10.04 LTS (Lucid) . It is finding all the packages. You try apt-get update then try to install the postfix