Tuesday, September 8, 2020

 

Configuring Sendmail with a Smart Host and SMTP Authentication

In this blog post, we’ll examine how to edit the sendmail. mc file to configure Sendmail to relay mail through an external SMTP service, such as SMTP2GO.

This setup will be userfull when:

  • You want to send emails through a third-party SMTP provider.

  • Your server is blocked from sending mail directly on port 25.

  • You must authenticate with your SMTP provider using a specific port (e.g., 2525).


🔧 Step-by-Step Sendmail Configuration

Here’s a snippet from the sendmail.mc file:

#dnl define(`SMART_HOST', `smtp.your.provider')dnl

define(`SMART_HOST', `mail.smtp2go.com')dnl

FEATURE(`authinfo')dnl

define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl

dnl #

Let’s break it down:

 Explanation of Each Line

1. Smart Host Definition

#dnl define(`SMART_HOST', `smtp.your.provider')dnl

This is a commented-out placeholder. You can use this format to set a different SMTP server if needed.

2. Actual Smart Host in Use

define(`SMART_HOST', `mail.smtp2go.com')dnl

This tells Sendmail to route all outbound mail through SMTP2GO.

3. Authentication Info Feature

FEATURE(`authinfo')dnl

This enables authentication support, allowing you to send email through a secure SMTP server that requires login credentials.

4. Relay Mailer Arguments

define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl

This specifies the port to use when connecting to the SMTP server. Here, we're using port 2525, a common alternative to port 25 (which is often blocked by ISPs).

5. Final Comment Line

dnl #

A dummy comment or placeholder, no operational effect.

Next Steps After Configuration

Once your sendmail.mc file is configured:

  1. Rebuild sendmail configuration

    m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
    
  2. Create the authinfo file Add your SMTP credentials in /etc/mail/authinfo:

    AuthInfo:mail.smtp2go.com "U:root" "I:your_username" "P:your_password"
    
  3. Hash the authinfo file

    makemap hash /etc/mail/authinfo < /etc/mail/authinfo
    
  4. Restart sendmail

    systemctl restart sendmail
    

Test the Configuration

Send a test email using mail or sendmail to confirm that everything is working.

echo "Test Email from Sendmail via SMTP2GO" | mail -s "Sendmail Test" your@email.com

Final Thoughts

Using a smart host like SMTP2GO makes your email delivery more reliable and helps avoid issues with ISPs blocking direct mail traffic. With a few lines in sendmail.mc, and some authentication setup, you're good to go!


No comments:

Post a Comment