Learn how to configure Sendmail to use Gmail as a Smarthost. Our Sendmail Support Team is here to help.
How to Configure Sendmail to Use Gmail as a Smarthost
Sendmail delivers emails directly to recipients’ mail servers by default. However, in many cases, it’s more reliable to use a smarthost, a relay server that handles outgoing emails for you. Configuring Sendmail to use Gmail’s SMTP servers as a smarthost ensures that the emails are sent through Google’s trusted infrastructure, improving deliverability and security.

Today, we will explore how to set up Sendmail with Gmail SMTP step by step.
An Overview
Step 1. Install Required Software
Before starting, confirm that Sendmail is installed on the system. If it’s missing, install it using the package manager.
Additionally, install SASL authentication libraries (such as `sasl2-bin`) to allow Sendmail to authenticate with Gmail’s servers.
For example, on Debian/Ubuntu systems:
sudo apt update
sudo apt install sendmail sasl2-bin
If you’re working on a lightweight system, you might also come across BusyBox Sendmail configuration, which behaves differently and requires separate adjustments.
Step 2. Configure Authentication
Next, create a file to store the Gmail login credentials:
sudo nano /etc/mail/auth/client-info
Then, add the following lines, replacing `YOUR_EMAIL@gmail.com` and `YOUR_PASSWORD` with the Gmail account details:
AuthInfo: "U:YOUR_EMAIL@gmail.com" "I:YOUR_EMAIL@gmail.com" "P:YOUR_PASSWORD"
For security, make sure the file is readable only by root:
sudo chmod 600 /etc/mail/auth/client-info
Step 3. Generate SASL Hash
Convert the authentication file into a database format that Sendmail can read:
sudo makemap hash /etc/mail/auth/client-info.db < /etc/mail/auth/client-info
If you’re unfamiliar with access databases in Sendmail, you may also want to review how to rebuild the Sendmail access DB when updating rules for relays and permissions.
Step 4. Edit Sendmail Configuration
Now, configure Sendmail to use Gmail’s SMTP server as a smarthost.
So, open the `sendmail.mc` configuration file:
sudo nano /etc/mail/sendmail.mc
Then, add the following lines at the end of the file:
define(`SMART_HOST',`[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
This tells Sendmail to use Gmail’s SMTP server on port 587 with authentication.
Step 5. Rebuild Sendmail Configuration
Once the changes are made, rebuild the Sendmail configuration file:
sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Step 6. Restart Sendmail
Restart the Sendmail service to apply the new configuration:
sudo service sendmail restart
At this point, Sendmail should be relaying all outgoing emails through Gmail’s SMTP servers.
For additional security, many admins integrate antivirus filtering at this stage. If that’s your goal, consider adding a milter like ClamAV. Here’s a guide on setting up Sendmail with ClamAV milter
.
Step 7. Test Email Delivery
To confirm that everything is working, try sending a test email:
echo "This is a test email" | mail -s "Test" recipient@example.com
If configured correctly, the email will be delivered via Gmail’s infrastructure.
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
Configuring Sendmail to use Gmail as a smarthost is a reliable way to send emails securely while leveraging Google’s infrastructure. By setting up authentication, editing the Sendmail configuration, and restarting the service, we can improve email deliverability and avoid common issues with direct server-to-server delivery.
In brief, our Support Experts demonstrated how to configure Sendmail to use Gmail as a Smarthost.
