How to Setup mail server on Linux

0
1291
How to setup mail server in centos

Here will see how to setup mail server on Linux server,

Step 1: Postfix Configuration

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.cfconfiguration 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 mailserver 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).

Step 2:  Dovecot Configuration

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 mailclients 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.

Step 3: Restart Services

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 the system-switch-mail 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.

Step 4: Check mail

Once you install and configured all postfix and dovecot, now we can sent test mail and check, is the mail is working or not.

In linux we can sent mail through either commend line or mail clients like squirrel mail, mutt etc. here we can use commend line for send mail with attachment

#mail –s “Hi” xyz@example.com < file name

s – Subject Line

NO COMMENTS