Install Postfix MTA and configure smarthost

I am planning to implement Network Monitoring tool to monitor my company’s IT infrastructure. As part of that project I decided to implement Nagios on a Ubuntu Server 12.04.1 LTS. So far during my career I have never worked on Linux, but hoping to be fluent with it in a short run. When our IT infrastructure will be monitored by Nagios, and when something goes wrong/abnormal alerts will be generated through email to all the administrators. However to fulfill this requirement it is necessary to install Mail Transfer Agent (MTA) on the Ubuntu Server. I selected Postfix because it is easy to configure as compared to sendmail. Below are the steps to install Postfix and configure it as a smarthost relay server.

Install Postfix MTA

1. sudo apt-get install postfix

2. Select “Internet with smarthost” when prompted for type of mail configuration. We selected this option because we want to relay notification email generated by through external mail server instead of allowing Linux box to send directly.

Postfix Configuration : Internet with smarthost

3. Type domain name when it asks for System mail name.

Postfix Configuration : System mail name

4. Enter the FQDN or IP Address of the smarthost. If SMTP port supported by smarthost are non-standard then it can be entered like host_name:port.

Postfix Configuration : SMTP relay host

5. The configuration we did so far haven’t asked us to supply SMTP credential for smarthost. If the smarthost allows unauthenticated SMTP relay then we will be able to send email otherwise to configure credential for SMTP smarthost follow below steps:

Configure Postfix MTA as smarthost relay Server

1. Create a password map file by issuing command sudo vi /etc/postfix/smarthost_passwd.

2. Add smarthost_name USERNAME:Password line in the password map file. Replace smarthost_name, username and password with actual one e.g. example.com someone@xyz.com:********

3. Since /etc/postfix/smarthost_passwd file contains plain text credentials and hence it’s worth to setup strict permission over it.

  • Change the file owner user and group by issuing below command
sudo chown root:root /etc/postfix/smarthost_passwd
  • Modify the permissions using below command
sudo chmod 600 /etc/postfix/smarthost_passwd

4. Create a hash from map file (remember to do this each time you change map file i.e. smarthost_passwd)

sudo postmap /etc/postfix/smarthost_passwd

5. Configure /etc/postfix/main.cf as show below

relayhost = smarthost_fqdn_or_ip

smtp_sasl_auth_enable = yes

smtp_sasl_password_maps = hash:/etc/postfix/smarthost_passwd

smtp_sasl_security_options = noanonymous

6. Restart Postfix daemon

sudo /etc/init.d/postfix restart

7. To test if the configurations done so far are working you will required to send a test email from Command Line. To know more visit Send emails Using Telnet. Below are the SMTP conversation captured while I tested the smarthost configuration.

gopalthorve@linux-srv1:~$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 linux-srv1 ESMTP Postfix (Ubuntu)
helo gmcil.com
250 linux-srv1
mail from:
250 2.1.0 Ok
rcpt to:
250 2.1.5 Ok
data
354 End data with .
Hi,
This is test mail. Sent from Postfix linux server to test authenticated
smart host relay configuration.
Thanks!!!
.
250 2.0.0 Ok: queued as DCC7FE01D2
quit
221 2.0.0 Bye
Connection closed by foreign host.
gopalthorve@linux-srv1:~$

8. If all the configuration done are okay then you will receive test email sent from telnet session within a few minutes. If you don’t get any email, then to look for what is going wrong you will need to verify Postfix logs. Postfix logs are stored in /var/log/mail.log.

gopalthorve@linux-srv1:~$ sudo tail /var/log/mail.log
[sudo] password for gopalthorve:
Nov 3 23:07:18 linux-srv1 postfix/smtpd[6670]: connect from localhost[127.0.0.1]
Nov 3 23:08:00 linux-srv1 postfix/smtpd[6670]: DCC7FE01D2: client=localhost[127.0.0.1]
Nov 3 23:09:02 linux-srv1 postfix/cleanup[6673]: DCC7FE01D2: message-id=<20121103173800.DCC7FE01D2@linux-srv1>
Nov 3 23:09:03 linux-srv1 postfix/qmgr[5751]: DCC7FE01D2: from=, size=422, nrcpt=1 (queue active)
Nov 3 23:09:05 linux-srv1 postfix/smtp[6693]: DCC7FE01D2: to=, relay=aaa.bbb.ccc.ddd[aaa.bbb.ccc.ddd]:25, delay=75, delays=73/0.1/1.2/0.65, dsn=2.0.0, status=sent (250 OK id=1TUhgW-0008BS-J0)
Nov 3 23:09:05 linux-srv1 postfix/qmgr[5751]: DCC7FE01D2: removed
Nov 3 23:09:08 linux-srv1 postfix/smtpd[6670]: disconnect from localhost[127.0.0.1]
gopalthorve@linux-srv1:~$

Do let me know if you find any correction to this post. Thanks!!!

Related Posts

One thought on “Install Postfix MTA and configure smarthost

Leave a Reply

%d bloggers like this: