MSMTP (Simple Sendmail) with Google
Why Use MSMTP
MSMTP provides a simple way to send emails using a Gmail account or other SMTP providers. This is a straightforward solution that’s easy to configure.Configuration Script
The following script automates the MSMTP setup:Gmail and Exim4 As MTA With Implicit TLS
Why Use Exim4 with TLS
Unless you’re setting up your own mail server, you need a way to send emails from your server for system alerts and messages. This approach uses implicit TLS, making an encrypted connection from the start rather than upgrading an unencrypted connection.Important: Google no longer allows using your account’s password for authentication. You must enable 2FA and use an app-password.
Benefits
- Encrypted from start: Unlike STARTTLS which starts unencrypted then upgrades, this method establishes encrypted TLS connection immediately
- Long line support: Configuration includes fixes for exim4’s long line issues
- Dedicated account: Use a Gmail account specific to this server for better security isolation
Setup Steps
Configure exim4
Run the configuration wizard:Answer the prompts as follows:
| Prompt | Answer |
|---|---|
| General type of mail configuration | mail sent by smarthost; no local mail |
| System mail name | localhost |
| IP-addresses to listen on for incoming SMTP connections | 127.0.0.1; ::1 |
| Other destinations for which mail is accepted | (default) |
| Visible domain name for local users | localhost |
| IP address or host name of the outgoing smarthost | smtp.gmail.com::465 |
| Keep number of DNS-queries minimal (Dial-on-Demand)? | No |
| Split configuration into small files? | No |
Configure Gmail Credentials
Make a backup of the password file:Add your Gmail credentials to Secure the password file:
/etc/exim4/passwd.client:- Replace
[email protected]andyourPasswordwith your details - If you have 2FA/MFA enabled, use an app password
- Always check
host smtp.gmail.comfor the most up-to-date domains to list
Generate TLS Certificate
Create a TLS certificate for the encrypted connection:You’ll be prompted for certificate details. Enter your information as appropriate.
Configure TLS Settings
Create This enables TLS, requires it for smarthost connections, uses port 465, and fixes the long line issue.
/etc/exim4/exim4.conf.localmacros with the following content:Update Template Configuration
Make a backup of the template:Add this block to Add this block inside the
/etc/exim4/exim4.conf.template after the .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS ... .endif block:.ifdef MAIN_TLS_ENABLE block:Configure Mail Aliases
Add mail aliases to Add entries for all local accounts that exist on your server.
/etc/aliases for local accounts:Troubleshooting
If exim4 fails to deliver mail due to long lines, ensure you’ve addedIGNORE_SMTP_LINE_LENGTH_LIMIT = true to /etc/exim4/exim4.conf.localmacros as shown in Step 5.