Install Postfix (email server) in Linux

This article shows you how to install and configure a simple mail server called Postfix. It can be used to send emails or act as a email relay server for internal network wherein only one Server is allowed access to Internet and then all clients hosts will redirect email to this Postfix email relay server.

Mail root@hostnameSubject: This is test email
Her is where the message goes
.
EOT

Now simply type "mail" and it will show you the mail received locally.

Now if you want the Alias FROM: in Postfix, carry out the below changesEdit /postfix/generic

# vi /etc/postfix/generic

root mydomain.ltd

Edit postfix/main.cf

# vi /etc/postfix/main.cf

smtp_generic_maps = hash:/etc/postfix/generic

Save and quit the file

# postmap /etc/postfix/generic
# postfix reload

Now change the name in passwd file from root to your preferred name

# vi /etc/passwd

root:x:0:0:Own Name:/root:/bin/bash

Save and quit the file

NOTE: If you receive an error "Postfix: /usr/sbin/sendmail: No such file or directory". There might be a symlink which is missing between sendmail and postfix. Create one.

# ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail

If sending emails in POSTFIX through external SMTP, follow the steps below.You will need to make changes in your configuration file (in standard postfix configuration it would be /etc/postfix/main.cf). You need to add at the end of configuration file following lines:

Postfix have to know your account login and password as most SMTP servers would not allow to rely emails from unauthorized connections. You will need to make a password file “/etc/postfix/sasl_passwd”.

If you will get an output like “username:password” it means that password file has been generated correctly.You can remove “/etc/postfix/sasl_passwd“. POSTFIX will not need it anymore.Its all ready now and you can Restart your POSTFIX and test it.

You can also restrict the Recipients Clients for email if you want to by following the steps below.Create a file called “rbl_override” with the allowed IP's of hosts in it.