Saturday 3 December 2016

Configure SMTP server in Linux

Installation

You will be astonished to see how simple it is to install the Postfix mail server. All you need to do is follow these steps:

1) Open up the shell or (terminal) window.
2) Type the command:

yum install postfix – y.

That's it! The installation will spontaneously start the Postfix daemon for you. As soon as the installation is complete, you can try it out to make sure that you can link to your Postfix server with the command:

telnet localhost 25

It will produce something on the screen like:

Trying 127.0.0.1…
Connected to www.testemail.com
Escape character is '^]'.
220 www.oslibrary.com ESMTP Postfix

Note: Here www.testemail.com is my hostname

You will have to use your particular FDQN in the above command (instead of mymail.com). You will get the same output when you use localhost. If not, you will have to crosscheck to make sure that your domain is pointing to your server or port 25 in the normal scenario.

Configuration of SMTP mail server

Configuring Postfix

The Postfix mail server has one important configuration file /etc/postfix/main.cf.

Open the file in the text editor and look for the following section:

Myhostname=
inet_interfaces= all
inet_protocols= ipv4
alias_maps = hash: /etc/aliases
mydestination =
mynetworks =

These are the sections of the configuration file you must emphasize on. And, I must say, there isn't much to do. Underneath are the sections you need to configure:

myhostname: This parameter specifies the internet hostname of this mail daemon. The default is to use the fully-qualified domain name.

mydestination: This parameter specifies which destinations this machine will deliver locally. Use the configuration locally which has been provided by default in the server and change the localhost to the domain name.

mynetworks: This line is a bit riskier. This entry will define authorized destinations that mail can be relayed from. If you are thinking to add your subnet here, there are partial chances of its success.

You can go with mynetworks entry that looks like:

mynetworks = 127.0.0.1/8

The above entry is a safe entry and defines local machines only.

The inet_interfaces parameter specifies the network interface addresses on which it receives mails. By default, the software ensures all active interfaces on the machine. The parameter also controls the delivery of mails to the user@[ip.address].

inet_protocols= ipv4

By default, it is set to IPv4 to ensure faster delivery of mails.

Now, save all these in your configuration file accordingly and restart your mail server with the command:

Service postfix restart

Your mail server should be active and running.

Creating users

Since this is a Linux mail server, you have to make sure that you have a user name that resembles every email address you need. You can create users with the command:

useradd -m USERNAME (USERNAME is the real name of the user).

The next step is to give the username, a password with the command:

passwd USERNAME

Again, the USERNAME is the real username and you will be encouraged to enter the new password twice.

Testing Your Server

You can use mail utils package to install necessary things to send the mails by using the command:

Yum install mail x – y

After this, try any mail Id by typing:

Mail (mailid)

It will ask the subject. Enter the content you want to send.

After completing, exit and end the mail by using a dot (.)

No comments:

Post a Comment