MTPSMTP is an acronym for Simple Mail Transport Protocol. This is the protocol used by the email systems to transfer mail messages from one server to another. This protocol is essentially the communications language that the MTAs use to talk to each other and transfer messages back and forth.
Many system administrators are now using Postfix or Qmail to handle email. Both are faster and easier to configure than Sendmail. For the purposes of this chapter, therefore, we will look at Postfix as an MTA because of its simplicity and popularity. If you would prefer to use Sendmail there are many books that specialize in the subject and that will do the subject much more justice than we can in this chapter.
/sbin/service sendmail statusIf sendmail is not running the following output will be displayed:
sendmail is stoppedIf sendmail is running you will see the following:
sendmail (pid 2138) is runningIf sendmail is running on your system it is necessary to stop it before installing and configuring Postfix. To stop sendmail run the following command as super user:
/sbin/service sendmail stopThe next step is to ensure that sendmail does not get restarted automatically when the system is rebooted. The first step is to find out which run levels will automatically start sendmail. To do this we can use the chkconfig command-line tool as follows:
/sbin/chkconfig --list | grep sendmailThe above command will typically result in output similar to:
sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:offThis means that if the system boots into runlevels 2, 3, 4 or 5 then the sendmail service will automatically start. To turn off sendmail we can once again use the chkconfig command as follows:
/sbin/chkconfig sendmail offThe chkconfig tool defaults to changing the settings for runlevels 2, 3, 4 and 5. You can configure for specific runlevels using the –levels command line option if necessary.
To verify the settings run chkconfig one more time as follows:
/sbin/chkconfig --list | grep sendmailAnd check that the output is as follows:
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:offSendmail is now switched off and configured so that it does not auto start when the system is booted. We can now move on to installing Postfix.
rpm -q postfixIf rpm reports that postfix is not installed, it may be installed as follows:
yum install postfixThe yum tool will download and install postfix, and configure a special postfix user in the /etc/passwd file.
The key options in the main.cf file are:
myhostname = mta1.domain.com
mydomain = domain.com
myorigin = $myhostname
inet_interfaces = $myhostnameOther settings will have either been set up for you by the installation process or are not needed unless you are feeling adventurous and want to configure a more sophisticated email system.
The format of myhostname is host.domain.extension. For example if your Linux system is called MyLinuxHost and your internet domain is MyDomain.com you would set the myhostname option as:
myhostname = mylinuxhost.mydomain.comThe mydomain setting is just the domain part of the above setting. For example:
mydomain = mydomain.comThe myorigin and inet_interfaces options use the settings we have just created so do not need to be changed (although the inet_interfaces may be commented out by default so you should remove the # at the beginning of this particular line in the main.cf file).
/usr/sbin/postfix startThe postfix process should now start up. The best way to check that everything is working is to check your mail log. This is typically in /var/log/maillog and should now contain an entry that looks like:
Nov 21 13:05:46 mylinuxhost postfix/postfix-script: starting the Postfix mail system Nov 21 13:05:46 mylinuxhost
postfix/master: daemon started -- version 2.2.5, configuration /etc/postfix
As long as you don't see any error messages you have successfully installed and started Postfix and you are ready to set up a mail client and start communicating with the outside world.To configure Postfix to start automatically at system startup, run the following command in a Terminal window:
/sbin/chkconfig --level 345 postfix on
Postfix ConfigurationThe following explanation is a step-by-step instruction on the sections that you need to modify in main.cf
Postfix offers a nice feature called SOFT BOUNCE, this feature can be used when you are working on an already setup mail server. When this feature is active the server will still queue messages during testing time.
Domain for Outbound mail
Sending MailBecause we are using a domain name, uncomment the following line, and read ahead to create an alias database.
myorigin = $mydomain
Domain for Inbound
Receive mailDo not enable any interface, instead create a file called destination in /etc/postfix/destination and place the domain-name for the destination in that file. In the RECEIVING MAIL section, find the line:
mydestination = $myhostname, localhost.$mydomain,Edit this line to point to the destination file:
mydestination =$myhostname,localhost.$mydomain, /etc/postfix/mydestinationNext edit the mydestination file and enter your domain-name(s):
[root@server2 postfix]# vi mydestination
Create the AliasesIn the ALIAS DATABASE SECTION, uncomment the line:
Alias_maps = hash:/etc/postfix/aliases
Next execute the following command to create the database. Note that the database will be created in the directory /etc/postfix/
[root@server2 postfix]# postalias /etc/postfix/aliases
That's it. Restart postfix. You now should be able to send and receive email from your domain name.
Virtual Domains with PostfixWe have successfully configured the email server to send and receive email at the default domain (Primary domain), in this case netcontrol.org. All users in the system can send and receive email under netcontrol.org by default. If you already updated mydestination file and included other domains; that is not enough for virtual mail servers.
Since onetraining.net is a virtual domain in this example, I will use it to set the mail server in the virtual domains.
Configuring the virtual domain email server
Virtual Address MappingWe need to go back and edit the main.cf file to set this virtual address. All users in each domain have to be able to receive and send email. And of course it has to get to its right destination.
To implement this, locate and insert:
# ADDRESS REDIRECTION (VIRTUAL DOMAIN)
# Insert text from sample-virtual.cf if you #need virtual domain support.virtual_maps = hash:/etc/postfix/virtual_maps
Note that virtual_maps is hashed just like aliases, the next step is to create a file in /etc/postfix. Call it virtual_maps and include the virtual domains in it.
[root@server2 postfix]# vi virtual_maps
In this file you will place all your users for the virtual domains, and after editing this file you have to create the database virtual_maps.db
At your command line (console) type the following:
[root@server2 postfix]# postmap virtual_maps < virtual_maps
Restart postfix and you are ready to go. Test the system with your user under the virtual domain, you should be able to receive and send email.