Send an email with a CLI command


Requirements


Setup the Config

Install msmtp and set up the defaults.

1mkdir ~/.config/msmtp/
2cat > ~/.config/msmtp/config << EOF
3defaults
4tls on
5auth on
6
7EOF

You'll need to fill in some variables, like your provider's hostname and SMTP port. The ${pass_name} is just the pass command which gives your email password.

1name=posteo
2host=posteo.de
3port=587
4user=bob@posteo.net
5pass_name=posteo.net

With those in, add that default account.

1cat >> ~/.config/msmtp/config << EOF
2
3account ${name}
4host ${host}
5port ${port}
6user ${user}
7from ${user}
8passwordeval pass ${pass_name}

Finally, set this as the default account:

1account default : ${account} >> ~/.config/msmtp/config

Write an Email

Fill out the headers in a file called mail.

From: MSMTP ${user}
Subject: Pipes
To: ${recipient_name} <${recipient_email}>

A pipe gives a wise man time to think and a fool something to stick in his
mouth.

Send

Send the email:

1msmtp -t bindrpg@posteo.uk < mail