msmtp

Basic Setup

Msmtp is an smtp client that you can use from the command line or in combination with other tools / scripts.

Example Setup file ~/.msmtprc

# Set default values for all following accounts.
defaults
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        ~/.msmtp.log

# MyAccount
account        account-name
host           smtp.server.com
port           587
from           username@example.com
user           username
password       plain-text-password # Optional. If omitted, you will be prompted  

# Set a default account
account default : account-name

Then, do

chmod 600 ~/.msmtprc

To send a mail:

user@host: ~$ echo "Hello world!" | msmtp -a default addressee@example.com

To send one with a subject:

user@host: ~$ cat << EOF | msmtp -a default addressee@example.com
> Subject: Test
> 
> Foo body bar
> EOF

Note the empty line that delimits the header from the body.

You can obviously also pipe the content from a text file or the output of another command to msmtp rather than reading it from stdin as shown above...