Sie sind auf Seite 1von 7

Introduction

This article is aimed at beginners who wish to set up a basic email server. Basic system administration knowledge would be an advantage and the ability to install software and edit configuration files is essential. The article was written for CentOS 5 but should be equally applicable to earlier versions. Later versions may differ. There are many different scenarios and combinations that can be used when setting up an email server (far to many to cover here), so this article makes some basic choices for you, such as the software we will use (postfix and dovecot). Other options are required to be altered by the user, such as your network addresses and domain names. More advanced options such as virtual domains and users are outside the scope of this article and will not be covered herein. This article uses postfix as the mail transport agent (MTA), as opposed to sendmail, the default MTA for CentOS 5 (postfix is the default in CentOS 6). Dovecot is used to allow users to access their email by either imap or pop protocols. We assume a domain name of example.com which should be changed by the reader and can be either a real domain name for a fully qualified email server or a fake domain name if you only wish to implement an internal mail server. We assume that the physical mail server (host) is mail.example.com and is located at the private IP address 192.168.0.1 (this should be changed to suit the readers needs). The email server will provide email accounts via standard user system accounts and users will access their email using their system account username and password. We will assume a user called John Smith who has a system account under the login name of john.

2. Installation
The first thing we need to do is install the requisite software. The easiest way to do this is with yum from the command line: yum install postfix dovecot system-switch-mail system-switch-mail-gnome Yum should automatically resolve any dependencies. Dovecot is dependent on mysql and perl, so these will likely be installed too if they are not already installed on the system. Alternatively, we can skip 'system-switch-mail' and 'system-switch-mail-gnome' installation and remove the default MTA 'sendmail', this will make 'postfix' the default MTA in our system. yum install postfix dovecot yum remove sendmail Please note that the default MTA in CentOS 5 is sendmail. If you do not make postfix the default MTA, updating postfix may cause the default MTA to revert to sendmail.

3. Configuration
Next we need to configure the various parts of our email server.

3.1. Postfix
Postfix configuration files are stored in /etc/postfix. The two main postfix configuration files are master.cf and main.cf, although we will only be dealing with main.cf here. First we are going to make some additions or changes to the main.cf configuration file. The following lines should be added, edited or uncommented:

myhostname = mail.example.com mydomain = example.com myorigin = $mydomain inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mynetworks = 192.168.0.0/24, 127.0.0.0/8 relay_domains = home_mailbox = Maildir/ Note: Each line should start at the beginning of a new line and should not be preceded by white space or tabs. White space or tabs at the beginning of a line are treated as a continuation of the previous line, and if the previous line is a comment (#) line then the subsequent line is also treated as such. Further, inline comments should be avoided. Now lets take a look at each setting it turn to understand what we've just done: myhostname: is the host name of the system (i.e, the system is called mail or mail.example.com). mydomain: is the domain name for the email server (it can be a real or fake domain name). myorigin: is the domain name that locally-posted email appears to have come from and is delivered to. inet_interfaces: sets the network interfaces that Postfix can receive mail on. These need to include at least localhost and the local domain. mydestination: is the list of domains that will be delivered to (i.e, this server is the final destination for email addressed to these domains). mynetworks: is a list of trusted IP addresses that may send or relay mail through the server. Users attempting to send email through the server originating from IP addresses not listed here will be rejected. relay_domains: is a list of destination domains this system will relay mail to. By setting it to be blank we ensure that our mail server isn't acting as an open relay for untrusted networks. The reader is advised to test that their system isn't acting as an open relay here: http://www.abuse.net/relay.html home_mailbox: sets the path of the mailbox relative to the users home directory and also specifies the style of mailbox to be used. Postfix supports both Maildir and mbox formats and readers are encouraged to read up on the merits of each for themselves. However, in this article we have chosen to use Maildir format (a trailing slash indicates Maildir format. To specify mbox format, the reader would use home_mailbox = Mailbox).

3.2. Dovecot
The dovecot configuration file is located at /etc/dovecot.conf. The following lines should be added, edited or uncommented: protocols = imap imaps pop3 pop3s mail_location = maildir:~/Maildir pop3_uidl_format = %08Xu%08Xv # Required on x86_64 kernels login_process_size = 64 Again, looking at each option: protocols: specifies the protocols available to users to access their email. Dovecot supports

imap(s) and pop3(s), and any or all may be used. mail_location: specifies the format and location of each users mailbox. Here we see we are using maildir format and each user has their mailbox located at ~/Maildir. Examples for mbox format are provided in the configuration file. pop3_uidl_format: is required to fix a problem with Outlook 2003 accessing mailboxes via pop3 so it makes sense to set this (see the notes in the configuration file for more details). login_process_size: The release notes for CentOS 5.1 state that "the Dovecot package on x86_64 kernels requires the parameter "login_process_size = 64" to be added to /etc/dovecot.conf after an upgrade to CentOS 5.1". 32-Bit installations are unaffected and do not require this setting. Note: If you have any issues connecting with either imap or pop3 to dovecot, check the IMAP specific settings and POP3 specific settings sections of the dovecot.conf configuration file for workarounds. The available options mostly affect older mail clients and workarounds for Microsoft Outlook and Outlook Express. Note on dovecot and C6: With CentOS 6 the configuration moved to /etc/dovecot/dovecot.conf. Dovecot can be started without any further changes to the configuration file and will automatically listen for connections on the ports for pop3(s) and imap(s). Changes to suite your environment will probably be required.

3.3. Create users mailboxes


Next we need to create a mailbox for each user in their home directory and set the appropriate permission, so using our example user john: mkdir /home/john/Maildir chown john:john /home/john/Maildir chmod -R 700 /home/john/Maildir Note: If creating the user mailboxes as root then we must set ownership of the directory to the user.

3.4. Aliases
We are nearly finished. We have an email account set up for our user John Smith who logs in as john. His email address would be john@example.com . However, John may like to receive email as jsmith@example.com (or any other alias). We can achieve this by setting an alias for John using the system alias file (by default postfix uses /etc/aliases). We can also add aliases for other users, so for example we could also redirect root's email to John by adding the following to /etc/aliases: # Person who should get root's mail root: john # User aliases jsmith: john j.smith: john If you edit the aliases file to set up new aliases for users once postfix is running, you must rebuild the aliases database by running the newaliases command.

4. Starting the server


We are now ready to fire up our new email server. First we need to tell our system to use postfix as the MTA rather than the default sendmail. To do this, run thesystem-switchmail command and select postfix as the MTA. This will install the postfix service and set it to start automatically at runlevels 3, 4, and 5. Next we need to set the dovecot service to also automatically start at runlevels 3, 4, and 5, and start both services: chkconfig --level 345 dovecot on /etc/init.d/dovecot start /etc/init.d/postfix start at which point you should be up and running. Your email server should have no trouble sending and receiving email internally and sending external email. To receive external email on your domain, you will also need to configure MX records in DNS for your domain (ideally a PTR rDNS entry should also be configured through your ISP mapping your IP address to your domain). Don't forget to open any required ports on your Linux firewall depending what services you are running (SMTP 25; POP3 110; IMAP 143; IMAPS 993; POP3S 995) and enable port forwarding for those ports on any routers. If you make any changes to the postfix configuration file main.cf, you can either restart the postfix service or run the postfix reload command to update the changes.

Dovecot installation and configuration on CentOS


Article ID: 2009 Last updated on October 11, 2012 Authored by: Lee Jelley (7 Comments)

Introduction If you've installed postfix to operate as the SMTP service on a would-be email server you might still need a way to retrieve the incoming mail from your server. To that end, in this article we'll talk about installing and configuring Dovecot. Dovecot is an open-source IMAP and POP3 server application which was designed specifically for Linux/Unix Operating Systems. Dovecot retrieves emails from Postfix and delivers them to the relevant mailbox on the server. You can get your mail through Dovecot using either of the POP3 or IMAP protocols. Prerequisites Operating System and version: Linux - CentOS 6.0 and above. Postfix installed.

Intended purpose for document: Basic installation and configuration of Dovecot. Target Audience: System Administrators, Mail Administrators, Postmasters. Installation

The first thing we will need is to download the Dovecot package. This command will install it: sudo yum install dovecot

Configuring Dovecot The next step is to configure the Dovecot services in the config file at /etc/dovecot/dovecot.conf - use whatever editor you like for the task. sudo nano /etc/dovecot/dovecot.conf The following lines will need to be uncommented and if necessary changed to reflect your plans for the environment: protocols = imap pop3 mail_location = maildir:~/Maildir protocols - This specifies the protocols that are available for users to access their email. mail_location - This specifies the format and the location of each user's mailbox.

Authentication process file Next we will configure the authentication process file. This config file can be located at /etc/dovecot/conf.d/10auth.conf -use the text editor of your choice for this task. sudo nano /etc/dovecot/conf.d/10-auth.conf The following line will need to be uncommented and if necessary changed to reflect your plans for your environment: auth_mechanisms = plain login auth_mechanisms - This specifies the way in which the email client authenticates with Dovecot.

Mail location To set the location for your mail use the configuration file at /etc/dovecot/conf.d/10-mail.conf. sudo nano /etc/dovecot/conf.d/10-mail.conf Either add or uncomment the line below in the configuration file. mail_location = maildir:~/Maildir

Postfix smtp-auth Next change the configuration file to configure the unix socket for postfix smtp-auth. This can be found at/etc/dovecot/conf.d/10-master.conf sudo nano /etc/dovecot/conf.d/10-master.conf Comment out the below lines first. #unix_listener auth-userdb {

#mode = 0600 #user = #group = #} Now edit these lines in the same file. # Postfix smtp-auth unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix }

POP3 configuration Finally we need to configure the pop3.conf file. This will allow some older or lesser-used email clients to connect and transmit correctly. This file can be found at /etc/dovecot/conf.d/20-pop3.conf. sudo nano /etc/dovecot/conf.d/20-pop3.conf We will now need to uncomment or add the following lines. pop3_uidl_format = %08Xu%08Xv pop3_client_workarounds = outlook-no-nuls oe-ns-eoh

Creating a Mailbox Now we'll add an example mailbox for a user Joe Bloggs (joe.bloggs) to send and receive emails. You may need to create a user for this example, or you can use an existing user. To make a new one: sudo useradd joe.bloggs You'll need to create the mail directory for your user. sudo mkdir /home/joe.bloggs/Maildir Next we need to give joe.bloggs ownership of the mailbox we have just created by changing its permissions. sudo chown joe.bloggs:joe.bloggs /home/joe.bloggs/Maildir sudo chmod -R 700 /home/joe.bloggs/Maildir

Starting Dovecot Once we have finished the mailbox creation we will need to make sure the Dovecot application will be run with the server upon restart. We'll use the chkconfig command for that purpose. sudo chkconfig --level 345 dovecot on The final step for Dovecot to be completed is to start the service. sudo service dovecot start Dovecot should now be up and running. Postfix Configuration We now need to go over to the Postfix directories and make the following changes in our main.cf file. The reason

for this final piece is so that we can allow our email client to connect to our newly built SMTP server. Exciting stuff! Please take a moment to navigate over to /etc/postfix/main.cf and open it with your chosen text editor. sudo nano /etc/postfix/main.cf Now we should add the following lines. smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks, check_relay_domains broken_sasl_auth_clients = yes smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth Once you have added the above lines you can exit the main.cf file and restart the Postfix service. sudo service postfix restart

Iptables port additions Now that we have enabled secure SMTP 'SSL' we should allow connections to port 587 by opening the port in iptables for our server. Add the rule for this port by entering the following command: sudo iptables -I INPUT 2 -p tcp --dport 587 -j ACCEPT After adding the SSL SMTP port we should also add the POP and IMAP ports along with their secure counterparts. sudo iptables -I INPUT 3 -p tcp --dport 110 -j ACCEPT sudo iptables -I INPUT 4 -p tcp --dport 143 -j ACCEPT sudo iptables -I INPUT 5 -p tcp --dport 993 -j ACCEPT sudo iptables -I INPUT 6 -p tcp --dport 995 -j ACCEPT Once these lines have been added we should save the iptables rules and restart iptables. sudo /etc/init.d/iptables save sudo /etc/init.d/iptables restart

Summary In this guide you've learned to configure and install a basic Dovecot setup. The steps you have covered today should have given you a solid foundation of a basic Dovecot install and configuration. From here you can explore the Dovecot package in more depth. Congratulations All that is left to do now is to congratulate you on finishing this configuration. With this brief guide you should be on track to a fully-functional mail server. Thanks for reading!

Das könnte Ihnen auch gefallen