Website-Suche

Mailserver mit Postfix, Dovecot und SquirrelMail in CentOS einrichten


Bevor Sie Postfix installieren, entfernen Sie Sendmail vom Server. Denn Sendmail ist der Standard-MTA in Redhat/CentOS.

[root@server ~]# yum remove sendmail

Voraussetzungen:

  • Der Mailserver sollte einen gültigen MX-Eintrag im DNS-Server enthalten. Navigieren Sie zu diesem Link, um zu erfahren, wie man einen DNS-Server einrichtet.
  • Firewall und SELinux sollten deaktiviert sein.
[root@server ~]# service iptables stop
[root@server ~]# service ip6tables stop
[root@server ~]# chkconfig iptables off
[root@server ~]# chkconfig ip6tables off
[root@server ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Starte den Server neu.

Szenario

In diesem Tutorial mein Testkasten

  • Hostname =server.ostechnix.com
  • IP-Adresse=192.168.1.200/24

Und mein Server ist mit dem richtigen MX-Eintrag im DNS-Server konfiguriert.

Installation

Postfix ist standardmäßig installiert. Wenn es nicht installiert ist, verwenden Sie den folgenden Befehl, um Postfix zu installieren.

[root@server ~]# yum install postfix

Konfiguration

Öffnen Sie die Postfix-Konfigurationsdatei /etc/postfix/main.cf. Suchen Sie die folgenden Zeilen und bearbeiten Sie sie wie unten gezeigt.

[root@server ~]# vi /etc/postfix/main.cf
myhostname = server.ostechnix.com ##line no 75 - uncomment and enter your host name
mydomain = ostechnix.com  ##line no 83 - uncomment and enter your domain name 
myorigin = $mydomain  ##line no 99 - uncomment
inet_interfaces = all  ##line no 116 - change to all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ##line no 164 - add $domain at the end
mynetworks = 192.168.1.0/24, 127.0.0.0/8  ##line no 264 - uncomment and add your network range
home_mailbox = Maildir/  ##line no 419 - uncomment

Starten Sie den Postfix-Dienst.

[root@server ~]# service postfix start
Starting postfix:                                          [  OK  ]
[root@server ~]# chkconfig postfix on

Test Postfix

Die in fettgedruckten Buchstaben gezeigten Befehle sollten vom Benutzer eingegeben werden.

Hinweis: Der Punkt nach dem Testbefehl ist wichtig.

[root@server ~]# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 server.ostechnix.com ESMTP Postfix
ehlo localhost
250-server.ostechnix.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<user1>
250 2.1.0 Ok
rcpt to:<user1>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test
.
250 2.0.0 Ok: queued as 117113FF18
quit
221 2.0.0 Bye
Connection closed by foreign host.

E-Mail prüfen

Navigieren Sie zum Benutzer-Mail-Verzeichnis und überprüfen Sie die neue Post.

[root@server ~]# cd /home/user1/Maildir/new/
[root@server new]# ls
1360236956.Vfd00I35afM181256.server.ostechnix.com
[root@server new]# cat 1360236956.Vfd00I35afM181256.server.ostechnix.com 
Return-Path: <user1@ostechnix.com>
X-Original-To: user1
Delivered-To: user1@ostechnix.com
Received: from localhost (localhost [IPv6:::1])
 by server.ostechnix.com (Postfix) with ESMTP id 117113FF18
 for <user1>; Thu,  7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.ostechnix.com>
Date: Thu,  7 Feb 2013 17:05:32 +0530 (IST)
From: user1@ostechnix.com
To: undisclosed-recipients:;
test

Das ist es. Postfix funktioniert jetzt.

Dovecot installieren

[root@server ~]# yum install dovecot

Dovecot konfigurieren

Öffnen Sie die Dovecot-Konfigurationsdatei /etc/dovecot/dovecot.conf. Finden Sie die Zeile und heben Sie die Auskommentierung wie unten gezeigt auf.

[root@server ~]# vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp

Öffnen Sie die Datei /etc/dovecot/conf.d/10-mail.conf und heben Sie die Auskommentierung der Zeile wie unten gezeigt auf.

[root@server ~]# vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir  ##line no 24 - uncomment

Öffnen Sie die /etc/dovecot/conf.d/10-auth.conf und bearbeiten Sie sie wie unten gezeigt.

[root@server ~]# vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no  ##line no 9 - uncomment and change from yes to no.
auth_mechanisms = plain login  ##line no 97 - add the text "login"

Öffnen Sie die /etc/dovecot/conf.d/10-master.conf und bearbeiten Sie sie wie unten gezeigt.

unix_listener auth-userdb {
    #mode = 0600
    user = postfix  ##line no 83 - uncomment and enter postfix
    group = postfix  ##line no 84 - uncomment and enter postfix

Starten Sie den Dovecot-Dienst.

[root@server ~]# service dovecot start
Starting Dovecot Imap:                                     [  OK  ]
[root@server ~]# chkconfig dovecot on

Test Dovecot

Die in fetter Schrift gezeigten Befehle sollten vom Benutzer eingegeben werden.

[root@server ~]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass user1
+OK Logged in.
list
+OK 1 messages:
1 428
.
retr 1
+OK 428 octets
Return-Path: <user1@ostechnix.com>
X-Original-To: user1
Delivered-To: user1@ostechnix.com
Received: from localhost (localhost [IPv6:::1])
 by server.ostechnix.com (Postfix) with ESMTP id 117113FF18
 for <user1>; Thu,  7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.ostechnix.com>
Date: Thu,  7 Feb 2013 17:05:32 +0530 (IST)
From: user1@ostechnix.com
To: undisclosed-recipients:;
test
.
quit 
+OK Logging out.
Connection closed by foreign host.
[root@server ~]#

Dovecot funktioniert jetzt.

Squirrelmail installieren

Installieren Sie zuerst das EPEL-Repository. Und installieren Sie das SquirrelMail-Paket aus dem EPEL-Repository.

[root@server ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@server ~]# rpm -ivh epel-release-6-8.noarch.rpm 
[root@server ~]# yum install squirrelmail
[root@server ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@server ~]# chkconfig httpd on
[root@server ~]#

Squirrelmail konfigurieren

Gehen Sie zum SquirrelMail-Konfigurationsverzeichnis und verwenden Sie den Befehl ./conf.pl, um die Konfiguration wie unten gezeigt zu starten.

[root@server ~]# cd /usr/share/squirrelmail/config/
[root@server config]# ./conf.pl 
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

Wählen Sie Option 1 und legen Sie die Organisationsdetails fest.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : Ostechnix
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : Welcome to Ostechnix webmail
5.  Signout Page           : 
6.  Top Frame              : _top
7.  Provider link          : https://ostechnix.com
8.  Provider name          : Ostechnix
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >>R

Drücken Sie R, um zum Hauptmenü zurückzukehren, und wählen Sie Option 2. Geben Sie Ihren Domainnamen ein und wählen Sie dovecot im Sendmail- oder SMTP-Parameter aus.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1.  Domain                 : ostechnix.com
2.  Invert Time            : false
3.  Sendmail or SMTP       : SMTP
A.  Update IMAP Settings   : localhost:143 (uw)
B.  Update SMTP Settings   : localhost:25
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >> S

Sobald Sie fertig sind, drücken Sie S, um Daten zu speichern, und drücken Sie Q, um zu beenden.

Fügen Sie die folgenden Zeilen am Ende der Datei httpd.conf hinzu.

[root@server ~]# vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>

Starten Sie den httpd-Dienst neu.

[root@server ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@server ~]#

Benutzer erstellen

[root@server ~]# useradd user1
[root@server ~]# useradd user2
[root@server ~]# passwd user1
[root@server ~]# passwd user2

Öffnen Sie den Browser von beliebigen Clients. Geben Sie Folgendes in die Adressleiste ein.

http://serveripaddress/webmail

oder

http://yourdomainname/webmail

Lassen Sie uns nun eine E-Mail von Benutzer1 an Benutzer2 erstellen. Beziehen Sie sich auf den untenstehenden Screenshot.

Dann melden Sie sich ab und wieder bei user2 an.

Das ist alles. Wir haben eine E-Mail von user1 erhalten. Wenn Sie irgendwelche Probleme mit der Konfiguration haben, posten Sie diese im Kommentarbereich.

Einen schönen Tag.