Yeah, you can send mail from your gmail account using command line.


You have two options here.

Gmail account settings

Either enable less secure apps in your Google account or Generate an app password .

Tools being used

For Arch Linux:

$ sudo pacman -S msmtp 

For Debian, Ubuntu and other Debian derived distributions:

$ sudo apt install -y msmtp

For Fedora, CentOS, Redhat etc:

$ sudo dnf install msmtp

Encrypt password

Using gpg, we are going to encrypt our password. I have a detailed video tutorial on gpg if you’re interested.

$ gpg -er 'your gpg keyID' -o ~/.gmail-password.gpg -

Now enter the password for your gmail from first step. Once done, enter Ctrl + D.

Configure msmtp

Paste this into ~/.msmtprc or if you want msmtp system wide so any user on this system can use this gmail account to send mails, copy it to /etc/msmtprc.

auth    on
tls     on
tls_starttls    on
tls_trust_file  /etc/ssl/certs/ca-certificates.crt
logfile     ~/.msmtp.log

account myaccount
port    587
from    your_gmail_address
user    your_gmail_address
passwordeval    "echo $(gpg --batch -q --decrypt ~/.gmail-password.gpg)"

account default: myaccount

Replace your_gmail_address with your gmail address.


Send a test mail

We are done now. Just send a test mail now.

$ echo "Just a test mail" | msmtp -a default 'some email address'

Use with mutt

You can use this msmtp setup with mutt which is suck less mail client and runs in a terminal. I have a detailed video tutorial on mutt here.

Thanks for reading.