Postfix configuration as a SMTP server on Linux

Postfix configuration introduction

Postfix is an alternative to sendmail. It is a free and opensource MTA. Postfix works as an SMTP server and provide defense against malware and spambots. However, postfix has a very limited features and requires third-party software. Postfix uses SMTP and Milter(Mail Filter) for full control over message and content.
Postfix works as a pipeline of processes, it means if one process fails in delivering the message, postfix passes the task to other process and the other process draws back and retries the process later. This makes postfix very flexible.
In this article we will learn about a part of mail server that is how to carry out postfix configuration to work as an SMTP server for sending mail via Gmail in Linux


Install required packages

The package mailx and cyrus-sasl-plain must be installed with postfix.

# yum install postfix mailx cyrus-sasl-plain

Start postfix

You must start the postfix service when it is installed. Please note that for CentOS7 and Redhat7 use the 'systemctl' command and for the lower version OS you can use the command 'service'.

# systemctl start postfix

or

# service postfix start
 
Stop sendmail

Sendmail is installed by default. Stop and remove the sendmail service.

# service sendmail stop
# yum remove sendmail

Enable boot start

Enable the postfix service to start at boot time.

# systemctl enable postfix

or

# chkconfig postfix on
Postfix configuration

Configure your postfix main.cf file as given below. The relayhost we are using here is smtp for gmail, because we will be carrying out postfix configuration to send mail via gmail smtp server. Change the hostname to your server hostname. Copy and paste the rest of the line at the bottom your main.cf file.

# vi /etc/postfix/main.cf
myhostname = mail.mailmania.com
relayhost = [smtp.gmail.com]:587
smtp_sasl_password_maps = hash:/etc/postfix/pass_sasl
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_auth_enable = yes
smtp_use_tls = yes
Create sasl file for postfix

Create a file named 'pass_sasl' under postfix directory as given. Edit it and give a valid gmail id and password.

# vi /etc/postfix/pass_sasl
[smtp.gmail.com]:587 username:password

Generate postfix lookup table

The postmap command will create a posfix database file. Posfix uses this database file as a lookup table. These lookup tables are used to store information for access control.

# postmap /etc/postfix/pass_sasl
Securing sasl_passwd file

Change the user and group ownership for the given file. You certainly don't want the hackers to gain access of your secure pass_sasl file.


Change the user and group ownership as given below.

# chown root:postfix /etc/postfix/pass_sasl*

Change the file permission.

# chmod 640 /etc/postfix/pass_sasl*
Reload postfix

You need to reload posfix after postfix configuration of main.cf file.

# systemctl reload postfix

or

# service postfix reload

Setup postfix as default

By now I assume you are done with postfix configuration and reloaded postfix service.
So if you have more than one mta installed on the smtp server, you have to set postfix as default mta. Verify it by below command and type selection number to choose postfix.

# alternatives --config mta
There are 2 programs which provide 'mta'.
Selection Command
-----------------------------------------------

* 1 /usr/sbin/sendmail.postfix

+ 2 /usr/sbin/sendmail.ssmtp
Enter to keep the current selection[+], or type selection number:1

Test mail

Test your mail by echo command to check if postfix working.

# echo "Testing mail." | mail -s "TEST" your_id@gmail.com

 


That's it with the article Postfix configuration as a SMTP server on Linux

You may also like:
SMTP server for Gmail : How to send email by Linux command
SSL certificate installation and configuration in postfix smtp mail server



 

Be the first to comment

Leave a Reply

Your email address will not be published.


*


shares