Send Email from Bash in Linux
Send emails from bash scripts using msmtp and any SMTP server (AWS SES, Gmail, etc.).
Install msmtp
sudo apt-get install msmtp -y
Configure SMTP Server
cat > ~/.msmtprc <<EOF
defaults
auth on
tls on
tls_starttls on
tls_certcheck off
account aws_ses
host email-smtp.eu-central-1.amazonaws.com
port 587
from FROM@EMAIL.COM
user USER
password PASSWORD
account default : aws_ses
EOF
Set Permissions
chmod 600 ~/.msmtprc
Send Email
printf "Subject: Test smtp ubuntu\n\nHello there from ubuntu." | msmtp -a aws_ses recipient@example.com
Send to multiple recipients with comma-separated addresses:
printf "Subject: Test smtp ubuntu\n\nHello there from ubuntu." | msmtp -a aws_ses user1@example.com,user2@example.com