Command Line Email on Ubuntu (nail version)

For a simpler, updated version of this guide, see this page:

This will be the first of two posts showing you how to configure the more recent versions of Ubuntu to send email from the command line as simply as humanly possible using your Gmail account for delivery. These instructions were originally posted on my old blog and on the Ubuntu forums site.

This guide covers using the nail program, which is my client of choice but is no longer in the main repositories. Find a guide for using mailx, which is part of the current Ubuntu repositories, here.

In 6 Fairly Easy Steps

1. Add the breezy repositories containing nail to your source file
Edit your sources list

$ sudo gedit /etc/apt/sources.list

Add the following lines at bottom. These will enable you to apt-get nail

# breezy repositories (added to install nail)
# see for more info
deb breezy universe

Don’t forget to update

$ sudo apt-get update

2. Install the needed programs

$ sudo apt-get install msmtp
$ sudo apt-get install nail

3. Install Thawte certificates for Gmail

EDIT: apparently no longer issues certs at the address below. So the ‘wget’ step will not work. According to this comment, you can downloaded the needed cert from I cannot vouch for this as my cert still works. But you might try downloading that and putting it your ~/etc/.certs directory if you’re having issues finding the cert.

This is necessary for Gmail. (Thanks to

$ mkdir -p ~/etc/.certs
$ chmod 0700 ~/etc/.certs
$ cd ~/etc/.certs
$ wget –no-check-certificate
$ unzip
$ cp Thawte Server Roots/ThawtePremiumServerCA_b64.txt ThawtePremiumServerCA.crt

4. Configure msmtp
This will open up a new msmtp configuration file

$ gedit ~/.msmtprc

Copy the following lines. Replace UPPERCASE text with your personal settings:

# config options:
logfile /tmp/msmtp.log

# isp account
account isp
auth login
port 25

# gmail account
account gmail
auth on
port 587
tls on
tls_trust_file /home/USER/etc/.certs/ThawtePremiumServerCA.crt

# set default account to use (from above)
account default : gmail

Change permission on this file or msmtp will complain:

$ chmod 600 ~/.msmtprc

5. Configure nail

$ gedit ~/.mailrc

Copy the following lines and replace UPPERCASE text with your personal settings:

# set smtp for nail
# ref:

# gmail account (default)
# $ nail -s "subject line" -a /path/file < /path/body.txt
set from=" (YOURNAME)"
set sendmail="/usr/bin/msmtp"
set message-sendmail-extra-arguments="-a gmail"

# isp account (add -A option to command line)
# $ nail -A isp -s "subject line" -a /path/file < /path/body.txt
account isp {
set sendmail="/usr/bin/msmtp"
set message-sendmail-extra-arguments="-a isp"

6. Run a test
Send a test message to your gmail account:

$ echo -e “testing email from the command line” > /tmp/test_email
$ nail -s “nail gmail test” < /tmp/test_email

Check your gmail account and you should have a message from yourself. You can also check your log:

$ gedit /tmp/msmtp.log

That’s it. You should now be ready to incorporate email into your bash scripts, which is great for making backups. I did successfully test this on an old laptop had installed Ubuntu 8.04 this weekend.

If you have any problems or questions, I’d recommend posting to the ubuntu forums thread as you’ll probably get a quicker response there.

Command Line Email on Ubuntu (nail version)

5 thoughts on “Command Line Email on Ubuntu (nail version)

  1. Mitch says:

    In previous comment single quotes are needed – not slashes:

    cp ‘Thawte Server Roots/ThawtePremiumServerCA_b64.txt’ ThawtePremiumServerCA.crt


  2. Alessandro says:

    I’ve unpacked the zip file but I can’t find the “ThawtePremiumServerCA_b64.txt”.
    Tried to go on with another file called “Thawte Premium Server CA.txt” but in the final test I get this error:
    send-mail: cannot set X509 trust file /home/USER/etc/.certs/ThawtePremiumServerCA.crt for TLS session: Error while reading file.
    send-mail: could not send mail (account default from /home/alex/.msmtprc)

    Can you help me?


  3. Eduardo says:


    This seems to be the answer for my problem. I have dotproject insatlled on my linux box and I need to configure the email notification (using a gmail account).

    How can I set msmtp as above for the whole system (not just for me)?

    Many thanks



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s