Configure SendMail to Use SMTP Relay

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives the steps to setup SendMail to use an SMTP relay also known as Smart Host to send out email through. If you don't have your own SMTP relay then your ISP SMTP Relay can be used. Although, keep in mind you may have to pass credentials to use your ISP or maybe even your enterprise SMTP relay.

This is useful when sending emails to external recipients to avoid anti-spoof and anti-spam filters to drop the messages because they are not coming from a whitelist SMTP relay. Be default it would use it's local SMTP mechanism which generally will be blocked by most SMTP systems.


Prerequisites

  • sendmail
  • sendmail-cf The files needed to reconfigure SendMail


Add SMTP Relay

  1. Edit Sendmail Make file /etc/mail/sendmail.mc
    vim /etc/mail/sendmail.mc
    
  2. Remove Comment for the following lines
    dnl define(`SMART_HOST', `smtp.your.provider')dnl
    
  3. Replace smtp.your.provider
    Example:
    define(`SMART_HOST', `relay.mydomain.com')dnl
    
    1. Do not use IP Address. It must be a FQDN.
    2. Beware of your DNS MX records causing issues.
  4. Regenerate SendMail Configuration File /etc/mail/sendmail.cf
    /etc/mail/make
    

Add Authentication (Optional)

If the SMTP relay requires authentication then do the following steps.

  1. Change to mail configuration directory
    cd /etc/mail
    
  2. Create /etc/mail/authinfo
    vim /etc/mail/authinfo
    
  3. Add a plain text line with SMTP FQDN and Credentials. Replace smtp.domain.com, USERNAME and PASSWORD
    AuthInfo:smtp.domain.com "U:USERNAME" "P:PASSWORD" "M:PLAIN"
    
  4. Create a hash map
    makemap hash authinfo < authinfo
    
  5. Add Authinfo to sendmail config
    vim /etc/mail/sendmail.mc
    
    FEATURE(`authinfo')
  6. Regenerate SendMail Configuration File /etc/mail/sendmail.cf
    /etc/mail/make
    


Restart Service

Restart the service with the appropriate command for your flavor and version of Linux.

service sendmail restart
/etc/init.d/sendmail restart
systemctl restart sendmail


Sources