Last Updated: December 31, 2020
· Osvaldo Zonetti

Sending emails easily from the command line

This tip is based on Ryan Yonzon's tip:

I just added some fixes I needed to make in order to run on Ubuntu.


Installing dependencies:

$ sudo apt-get install heirloom-mailx libnss3-tools sendmail -y

Creating the "certs" directory and importing the cert file from Gmail server:

$ mkdir ~/.certs

$ echo -n | openssl s_client -connect | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/gmail.crt

$ certutil -A -n "Google Internet Authority" -t "C,," -d ~/.certs -i ~/.certs/gmail.crt


Create the file ~/.mailrc and add the following configuration (updating accordingly to your account):

account gmail {
  set smtp-use-starttls
  set ssl-verify=ignore
  set smtp-auth=login
  set smtp=smtp://
  set from=" Doe)"
  set smtp-auth-password="s0m3p@zzW0rD"
  set ssl-verify=ignore
  set nss-config-dir=/home/path/to/.certs

Sending emails

$ echo "Email content" | mailx -A gmail -s "Email subject"