Simple Mail Transfer Protocol. SMTP is one of the important service in any production system. Now a days, mail notifications became important to monitor systems in real time. Hence, it becomes essential to know how to configure mail utilities on servers. To enable any mail program on system, SMTP is basic component. Its a very easy and quick procedure to setup smtp on servers.
- Hostname and IP address of SMTP server should be known (e.g. we will use mailserver.xyz.com 10.10.2.5)
- Client should be able to reach SMTP server over network
Its 5 steps procedure to setup SMTP client on Linux.
Add SMTP server entry in /etc/hosts file using vi editor or concatenate using echo command below.
# echo "10.10.2.5 mailserver.xyz.com" >> /etc/hosts
# cat /etc/hosts |grep -i mail
We need to edit macro configuration file /etc/mail/sendmail.mc. Search and edit below parameters in this file :
SMART_HOST',mailserver.xyz.com’) : Smart relay server name
confDOMAIN_NAME',xyz.com’)dnl : Valid domain name
- FEATURE(always_add_domain)dnl : always masquerades email address
allmasquerade')dnl: rewrite both from/to relative to the local machine.
- MASQUERADE_DOMAIN(xyz.com.’)dnl : Domain for masquerading emails
- MASQUERADE_AS(`xyz.com’)dnl : All mails masquerades as came from defined domain
Once above changes are done, you need to compile mc file so that all these changes of macro (mc) file will be transferred to config ( cf) file using m4 utility.
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Edit below parameters in /etc/mail/submit.cf so that mails will be submitted to defined domain.
Djxyz.com : Define this in case sendmail wont able to determine your domain.
DSmailserver.xyz.com : Smart relay host
Finally, restart mail services to take up this new configurations :
# service sendmail restart
# service postfix restart
You are done! Send test email with below command and check if you receive it.
# echo test |sendmail -v email@example.com
[<-] 220 mailserver.xyz.com ESMTP Postfix
[->] HELO testsrv2
[<-] 250 mailserver.xyz.com
[->] MAIL FROM:<firstname.lastname@example.org>
[<-] 250 2.1.0 Ok
[->] RCPT TO:<email@example.com>
[<-] 250 2.1.5 Ok
[<-] 354 End data with <CR><LF>.<CR><LF>
[->] Received: by testsrv2 (sSMTP sendmail emulation); Fri, 23 Dec 2016 02:29:07 +0800
[->] From: "root" <firstname.lastname@example.org>
[->] Date: Fri, 23 Dec 2016 02:29:07 +0800
[<-] 250 2.0.0 Ok: queued as 19F75822B8
[<-] 221 2.0.0 Bye
If you dont receive email, check logs under /var/log/maillog for troubleshooting.