A clean, lightweight way to send emails from a Linux workstation using Gmail SMTP—perfect for cron jobs, scripts, and system alerts.
sudo apt update
sudo apt install msmtp mailutils
To use Gmail’s SMTP server, you need an App Password (not your Gmail account password):
Go to: https://myaccount.google.com/apppasswords
Create the ~/.msmtprc file:
Add the following configuration (replace with your Gmail address and App Password):
account default
host smtp.gmail.com
port 587
auth on
user yourname@gmail.com
password your_app_password
from yourname@gmail.com
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
chmod 600 ~/.msmtprc
sudo mv /usr/sbin/sendmail /usr/sbin/sendmail.bak 2>/dev/null
sudo ln -s /usr/bin/msmtp /usr/sbin/sendmail
echo "This is a test email from msmtp." | mail -s "Test Email" recipient@example.com
cat ~/.msmtp.log