Sending emails from cmd line
Sep 1, 2024
You can send emails from cmd line in Ubuntu using mutt and gmail (which is useful for scripting notifications for example) as follows.
Set up Gmail app password
- Google account -> Security -> Enable
2-Step Verification - Google account -> Security -> 2-Step Verification -> App passwords -> Create
- Still, the above may not show app-specific password option, go to https://myaccount.google.com/apppasswords directly.
- App password should be a 16-character code
- Google account -> Security -> Enable
Set up
mutt- Install mutt
sudo apt-get install mutt- Create mutt config file
~/.muttrcwith the following content
set from = "{your-email}@gmail.com" set realname = "{sender}" set smtp_url = "smtp://{your-email}@[email protected]:587/" set smtp_pass = "{Gmail app password}" set ssl_starttls = yes set ssl_force_tls = yesMake sure to keep Gmail app password as it is, do not remove spaces. It should be
**** **** **** ****.Test
echo "Hello there" | mutt -s "test subject" recipient@example.comUsing mutt to mail to your designated sms email is basically how you programmatically send SMS notifications.