Simple SMTP Mail
Send emails via SMTP using msmtp command-line tool.
Configuration
Create a configuration file at ~/.msmtp/config with the following format:
account default
host <SMTP_SERVER>
port <PORT>
tls on
tls_starttls off
auth on
user <EMAIL_ADDRESS>
password <PASSWORD>
from <EMAIL_ADDRESS>Common SMTP Settings
Gmail:
- SMTP Server:
smtp.gmail.com - Port:
465(SSL) or587(TLS) - Note: Use App Password, not your regular password
QQ Mail:
- SMTP Server:
smtp.qq.com - Port:
465
Outlook/Hotmail:
- SMTP Server:
smtp.office365.com - Port:
587
163.com:
- SMTP Server:
smtp.163.com - Port:
465
Installation
1. Install msmtp
macOS:
brew install msmtpLinux (Debian/Ubuntu):
sudo apt install msmtpLinux (Fedora/RHEL):
sudo dnf install msmtp2. Configure SMTP
Edit ~/.msmtp/config:
nano ~/.msmtp/config3. Set Permissions
chmod 600 ~/.msmtp/configSending Email
Basic Email
echo "Body text" | msmtp recipient@example.comWith Subject
echo -e "Subject: Your Subject\
\
Body text" | msmtp recipient@example.comWith Subject and From Header
echo -e "Subject: Your Subject\
From: your@email.com\
\
Body text" | msmtp recipient@example.comHTML Content
echo -e "Subject: Your Subject\
Content-Type: text/html; charset=UTF-8\
\
<html>...</html>" | msmtp recipient@example.comTesting
Check if SMTP server is reachable:
msmtp --file=~/.msmtp/config --serverinfoTroubleshooting
- "Account not found": Check your config file path with
--fileflag - "Authentication failed": Verify username and password (or App Password)
- "Connection refused": Check port number and firewall settings
- "TLS certificate error": Try
tls_certcheck offin config (not recommended for production)