How to Configure Sendmail to Relay Through Gmail on Debian Linux 10 (Updated for 2024)

How to Configure Sendmail to Relay Through Gmail on Debian Linux 10 (Updated for 2024)

Important Notice: Debian 10 (Buster) Has Reached End of Life

As of June 30, 2024, Debian 10 (Buster) is no longer supported with Long-Term Security Updates. Using an unsupported operating system may expose your server to security vulnerabilities and compatibility issues.

We strongly recommend upgrading to a supported Debian version, such as Debian 12 (Bookworm).

🔗 For an updated guide on configuring Sendmail for Gmail relay on Debian 12 (Bookworm), visit:
How to Configure Sendmail to Relay Through Gmail on Debian 12 (Bookworm)

The instructions in this guide may still be useful for legacy systems running Debian 10, but we encourage all users to migrate to newer, supported Debian versions for security and performance reasons.

Introduction

If you’re running a Debian Linux 10 (Buster) server and need to configure Sendmail to relay emails through Gmail, recent security updates from Google require adjustments to traditional setups. As of 2022, Google has deprecated “Less Secure App Access,” meaning Sendmail must now authenticate using App Passwords instead of standard passwords. This guide will walk you through the updated process for configuring Sendmail with Gmail.

Prerequisites

  • A Debian Linux 10 (Buster) server with Sendmail installed
  • A Gmail or Google Workspace account
  • Two-factor authentication (2FA) enabled on your Google account
  • An App Password generated for Sendmail authentication

Step 1: Install Sendmail and Required Packages

Ensure Sendmail and necessary utilities are installed:

sudo apt update && sudo apt install sendmail mailutils sendmail-bin -y

Step 2: Generate an App Password for Gmail

Since basic authentication is no longer supported, you need to generate an App Password:

  1. Log in to your Google Account Security Page.
  2. Under “Signing in to Google,” enable 2-Step Verification if it’s not already active.
  3. Navigate to App Passwords and generate a new password for “Mail.”
  4. Copy the 16-character password—it will be used in Sendmail’s authentication configuration.

Step 3: Configure Sendmail to Use Gmail’s SMTP Relay

Edit or create the /etc/mail/authinfo file:

sudo nano /etc/mail/authinfo

Add the following line, replacing <your-email@gmail.com> with your Gmail address and <your-app-password> with the App Password you just generated:

AuthInfo:smtp.gmail.com "U:<your-email@gmail.com>" "P:<your-app-password>" "M:PLAIN"

Save and exit the file.

Convert it into a Sendmail database format:

sudo makemap hash /etc/mail/authinfo < /etc/mail/authinfo

Step 4: Update Sendmail Configuration

Edit /etc/mail/sendmail.mc:

sudo nano /etc/mail/sendmail.mc

Add or modify the following lines to configure Sendmail for Gmail relay:

define(`SMART_HOST', `smtp.gmail.com')
FEATURE(`authinfo', `hash -o /etc/mail/authinfo.db')
define(`RELAY_MAILER_ARGS', `TCP $h 587')
define(`ESMTP_MAILER_ARGS', `TCP $h 587')
FEATURE(`tls')
define(`confCACERT_PATH', `/etc/ssl/certs')
define(`confCACERT', `/etc/ssl/certs/ca-certificates.crt')

Save and exit the file.

Now rebuild Sendmail’s configuration:

sudo make -C /etc/mail
sudo systemctl restart sendmail

Step 5: Test the Configuration

Send a test email:

echo "Test email from Sendmail via Gmail" | mail -s "Test Email" recipient@example.com

Check the mail logs for any errors:

sudo journalctl -u sendmail --no-pager | tail -n 50

Alternative: Consider Switching to Postfix with a Relay

If you experience difficulties with Sendmail, consider using Postfix only if you’re using a proper SMTP relay (like Gmail, SendGrid, or Amazon SES). Running a standalone mail server without a relay may cause deliverability issues due to IP blacklisting.

To install Postfix:

sudo apt install postfix mailutils libsasl2-modules

Then configure it to use Gmail’s SMTP relay with an App Password.

Conclusion

With Google’s updated security policies, setting up Sendmail for Gmail relay requires using App Passwords instead of traditional authentication. By following these updated steps, your Debian 10 server can securely send emails through Gmail.

If you encounter persistent issues, ensure you are relaying through Gmail’s SMTP servers and not trying to send directly from your server’s IP, which can lead to deliverability problems. If necessary, consider a third-party email relay service for better email reliability.

For further troubleshooting, check Google’s SMTP relay documentation or your mail logs for debugging.

By William McGill

William McGill is an IT veteran and independent contractor with over 20 years of experience in technology, networking, and insurance. He blends tech expertise with real-world problem-solving, working across industries from flood insurance claims to system administration. While most of his writing focuses on tech, freelancing, and adapting to an ever-evolving digital landscape, he occasionally explores topics that simply spark his curiosity—because life isn’t just about work, but about being human.

2 comments

Leave a comment

Your email address will not be published. Required fields are marked *

William McGill