Top Menu

Thursday, February 5, 2015

How to configure sendmail with SMTP relay to your ISP

This is a very quick tutorial to show you how to configure sendmail (the default MTA for RHEL/CentOS) to relay mails to your ISP SMTP server (smarthost), allowing email out only. Expect a few technical terms in this document.

Why I need to do this?

To reduce the number of Spam mail on the Internet, many ISPs have blocked the outgoing SMTP port (25) access. Since all the SMTP servers in the cloud are communicating through port 25 only, you cannot send emails to any public domain when the port is blocked. But, there is always an alternative.

Install sendmail configuration tools

yum install sendmail-cf

Edit /etc/mail/

#declare the ISP SMTP server
define('SMART_HOST', 'your-smtp-server')

#listen to localhost only
dnl DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')dnl

#masquerade the from address

Apply the config

make -C /etc/mail

Input authentication information

Edit /etc/mail/authinfo

AuthInfo: "U:" "P:" "M:PLAIN"
#*my ISP requires auth info to be transferred in plain text

Apply the config
makemap hash /etc/mail/authinfo < /etc/mail/authinfo

Masquerade the from address

Edit /etc/mail/genericstable


Apply the config
makemap hash /etc/mail/genericstable < /etc/mail/genericstable

Allow relaying from these addresses
Edit /etc/mail/access

Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect: RELAY
Connect:192.168 RELAY

Apply the config

makemap hash /etc/mail/access < /etc/mail/access

Restart the service

service sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]


echo "This is a testing email for smarthost" | mail -s "Testing email from me" root

To read it, su as root and issue the command mail

To a public address:

echo "I send this one with the Linux command" | mail -s "Testing email from Sourav"

If you encounter any errors while testing, refer to /var/log/maillog  for details.

No comments:

Post a Comment