Setup Local Mail Server Using Postfix, Dovecot And Squirrelmail On OpenSUSE 13.x

Postfix is a free open source mail transfer agent (MTA). It is easy to administer, fast and as well as the secure MTA. It’s an alternative to Sendmail, which is the default MTA for RHEL.

Well, let us see how to setup a basic local mail server using Postfix, Dovecot and Squirrelmail On Opensuse, although it should work on SLES Servers.

If you want to setup mail server on RHEL based distros, follow the below article.

In Opensuse, it is quit different, because the commands and the folders destinations are not the same like Fedora/Centos.

For this tutorial, I use Opensuse 13.1 bit minimal installation, with Apparmor disabled. My test box details are given below.

OS : openSUSE 13.1 "Bottle"
IP Address : 10.1.1.174
Hostname: opensuse.unixmen.com

Prerequisites

1. Remove default MTA sendmail first if it’s already installed. Sendmail will not be installed by default in minimal installation, so you can ehloskip this step.

# zypper remove sendmail

2. Setup DNS server and add the Mail server MX records in the forward and reverse zone files. To install and configure DNS server, navigate to this link. And you’ll need to contact your ISP to point your external static IP to your mail domain.

3. Add hostname entries in /etc/hosts file as shown below:

# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.1.174    opensuse.unixmen.com   opensuse unixmen.local

Install Postfix

Let us install postfix package using the command:

# zypper in postfix

Configuring Postfix

Edit /etc/postfix/main.cf,

# vi /etc/postfix/main.cf

find and edit the following lines:

## Line no 677 - Uncomment and set your mail server FQDN ##
myhostname = server.unixmen.local

## Line 91 - Uncomment and Set domain name ##
mydomain = unixmen.local

## Line 107 - Uncomment ##
myorigin = $mydomain

## Line 121 - Set ipv4 ##
inet_interfaces = all

## Line 665 - Change to all ##
inet_protocols = all

## Line 676 - Uncomment ##\
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

## Line 268 - Uncomment and add IP range ##
mynetworks = 192.168.1.0/24, 10.1.1.0/24, 127.0.0.0/8

## Line 423 - Uncomment ##
home_mailbox = Maildir/

Save and exit the file. Start/restart Postfix service now:

# service postfix restart
# chkconfig postfix on

Testing Postfix mail server

First, create a test user called “mel“.

# useradd mel
# passwd mel

Access the server via Telnet and enter the commands manually shown in red colored text.

# telnet localhost smtp
opensuse:~ # telnet  localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 opensuse.unixmen.com ESMTP
ehlo localhost
250-opensuse.unixmen.com
250-PIPELINING
250-SIZE
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITM
mail from:<mel>     ## Type this - mail sender address##
250 2.1.0 Ok
rcpt to:<mel>     ## Type this - mail receiver address ##
250 2.1.5 Ok
data     ## Type this to input email message ##
354 End data with
welcome to unixmen mail server     ## Enter the boddy of the email ##.
     ## type dot (.) to complete message ##
250 2.0.0 Ok: queued as 3AB0E233B7
quit     ## type this to quit from mail ##
221 2.0.0 Bye
Connection closed by foreign host.

Now navigate to the user “mel“ mail directory and check for the new mail:

# ls /home/mel/Maildir/new/

Sample output:

opensuse:~ # ls  /home/mel/Maildir/new/
1399304353.V802I3257M677135.opensuse.unixmen.local

A new mail is received to the user “sk“. To read the mail, enter the following command:

# cat /home/mel/Maildir/new/1399304353.V802I3257M677135.opensuse.unixmen.local

Sample output:

Return-Path: <mel@unixmen.local>
X-Original-To: mel
Delivered-To: mel@unixmen.local
Received: from localhost (localhost [IPv6:::1])
        by opensuse.unixmen.com (Postfix) with ESMTP id 3AB0E233B7
        for <mel>; Mon,  5 May 2014 17:38:11 +0200 (CEST)
Message-Id: <20140505153831.3AB0E233B7@opensuse.unixmen.com>
Date: Mon,  5 May 2014 17:38:11 +0200 (CEST)
From: mel@unixmen.local

Mel from Unixmen team

Installing Dovecot

Dovecot is an open source IMAP and POP3 mail server for Unix/Linux systems. To install:

# zypper in dovecot
The following NEW packages are going to be installed:
  dovecot21 dovecot21-backend-mysql dovecot21-backend-pgsql dovecot21-backend-sqlite libpq5

Configuring Dovecot

Edit the file /etc/dovecot/dovecot.conf file,

# vi /etc/dovecot/dovecot.conf

Uncomment the following line:

## Line 20 - umcomment ##
protocols = imap pop3 lmtp

Edit file /etc/dovecot/conf.d/10-mail.conf file

# vi /etc/dovecot/conf.d/10-mail.conf

Make the changes as shown below:

## Line 24 - uncomment ##
mail_location = maildir:~/Maildir

Edit /etc/dovecot/conf.d/10-auth.conf

# vi /etc/dovecot/conf.d/10-auth.conf

And make the changes as shown below:

## line 9 - uncomment##
disable_plaintext_auth = yes

## Line 99 - Add a letter "login" ##
auth_mechanisms = plain login

Edit file /etc/dovecot/conf.d/10-master.conf,

# vi /etc/dovecot/conf.d/10-master.conf

Make changes as shown below:

## Line 91, 92 - Uncomment and add "postfix"
#mode = 0600
   user = postfix
   group = postfix

Start Dovecot service:

# service dovecot start
# chkconfig dovecot on
ln -s '/usr/lib/systemd/system/dovecot.service' '/etc/systemd/system/multi-user.target.wants/dovecot.service'

Testing Dovecot

It’s time to test Dovecot configuration. Enter the following command in Terminal:

# telnet localhost pop3

if you get issues to connect to pop3, please stop the Apparmor firewall.

 /etc/init.d/boot.apparmor stop

Enter the commands manually marked in red color:

telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user mel
+OK
pass 000000
+OK Logged in.
retr 1
+OK 407 octets
Return-Path: <mel@unixmen.local>
X-Original-To: mel
Delivered-To: mel@unixmen.local
Received: from localhost (localhost [IPv6:::1])
        by opensuse.unixmen.com (Postfix) with ESMTP id 3AB0E233B7
        for <mel>; Mon,  5 May 2014 17:38:11 +0200 (CEST)
Message-Id: <20140505153831.3AB0E233B7@opensuse.unixmen.com>
Date: Mon,  5 May 2014 17:38:11 +0200 (CEST)
From: mel@unixmen.local

Mel from Unixmen team
.

quit
+OK Logging out.
Connection closed by foreign host.

As you see in the above, Dovecot is working!

Working with mail in command modes little bit difficult for us. So we will install a webmail client called Squirrelmail to send/receive emails via a web browser.

Installing Squirrelmail

Make sure that you’ve installed and enabled Squirremail repository. Now install Squirrelmail using the following command:

zypper addrepo http://download.opensuse.org/repositories/server:php:applications/openSUSE_13.1/server:php:applications.repo
zypper refresh
# zypper in squirrelmail

Configuring Squirrelmail

Navigate to /srv/www/htdocs/squirrelmail/config directory and run the command conf.pl:

#  cd  /srv/www/htdocs/squirrelmail/config
# ./conf.pl

The following wizard will open. Enter choice “1″ to set your organization details:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages

D.  Set pre-defined settings for specific IMAP servers

C   Turn color off
S   Save data
Q   Quit

Command >> 1

The following wizard will open. Enter “1″ again to modify your organization details:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : SquirrelMail
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : SquirrelMail $version
5.  Signout Page           : 
6.  Top Frame              : _top
7.  Provider link          : http://squirrelmail.org/
8.  Provider name          : SquirrelMail

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> 1

Set your Organization name and press Enter:

We have tried to make the name SquirrelMail as transparent as
possible.  If you set up an organization name, most places where
SquirrelMail would take credit will be credited to your organization.

If your Organization Name includes a '$', please precede it with a \. 
Other '$' will be considered the beginning of a variable that
must be defined before the $org_name is printed.
$version, for example, is included by default, and will print the
string representing the current SquirrelMail version.

[SquirrelMail]: Unixmen

By this way, setup all the details such as organization title, logo, provider name in the above wizard. Once you done, press “S” to save changes and press “R” to return back to your main menu:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : Unixmen
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : SquirrelMail $version
5.  Signout Page           : 
6.  Top Frame              : _top
7.  Provider link          : http://squirrelmail.org/
8.  Provider name          : Unixmen Mail

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> s

Now enter “2″ to setup mail Server settings such as domain name and mail agent etc.:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages

D.  Set pre-defined settings for specific IMAP servers

C   Turn color off
S   Save data
Q   Quit

Command >> 2

Enter “1″, Enter your mail domain (ex. unixmen. local) and press Enter key.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings

General
-------
1.  Domain                 : localhost
2.  Invert Time            : false
3.  Sendmail or SMTP       : Sendmail

A.  Update IMAP Settings   : localhost:143 (uw)
B.  Change Sendmail Config : /usr/sbin/sendmail

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> 1
The domain name is the suffix at the end of all email addresses.  If
for example, your email address is jdoe@example.com, then your domain
would be example.com.

[localhost]: unixmen.local

Enter “3″ and change from sendmail to Postfix MTA (i.e. SMTP):

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings

General
-------
1.  Domain                 : unixmen.local
2.  Invert Time            : false
3.  Sendmail or SMTP       : Sendmail

A.  Update IMAP Settings   : localhost:143 (uw)
B.  Change Sendmail Config : /usr/sbin/sendmail

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> 3

Enter “2″ to switch from sendmail MTA to postfix.

You now need to choose the method that you will use for sending
messages in SquirrelMail.  You can either connect to an SMTP server
or use sendmail directly.3

  1.  Sendmail
  2.  SMTP
Your choice [1/2] [1]: 2

Now enter “S” followed by “Q” to save and exit Squirrelmail configuration.

Create a squirrelmail vhost in apache config file:

# vi /etc/apache2/httpd.conf

Add the following lines at the end:

Alias /squirrelmail /srv/www/htdocs/squirrelmail
<Directory /srv/www/htdocs/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>

Restart the Apache service:

# a2enmod rewrite
#  /etc/init.d/apache2   restart

Access Webmail

Now navigate to http://ip-address/squirrelmail or http://domain-name/squirrelmail from your browser. The following screen should appear. Enter the username and password of the user.

opensuse-postfix1 opensuse-postfix2

Create users

Create some users for testing. In my case i create two users called “test1“ and “test2“ respectively.

# useradd test1
# useradd test2
# passwd test1
# passwd test2

Sending emails from one account to another is tested under my machine and its working like a charm.

Cheers!