Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I send gpg encrypted mail automatically from the linux command line?

I'm a little stumped on this one, I've tried using mutt but it doesn't encrypt mail unless it's used interactively.

Does anyone know if you can use the build in mail command to do this some how?

share|improve this question

2 Answers 2

up vote 11 down vote accepted

try something like

gpg -ea -r "Recipient name" -o - filename | mail -s "Subject line" recipient@example.com

to send an ascii-armored, public-key-encrypted copy of the file "filename" to a person named "Recipient name" (who is in your gpg keyring) at email address recipient@example.com with the specified subject line.


echo "Your secret message" | gpg -ea -r "Recipient name" | mail -s "Subject" recipient@example.com

to send text directly rather than from a cleartext file on disk.

share|improve this answer
Does that sign the message (with your private key) as well? –  teeks99 Aug 6 '13 at 18:11
Add "s" to the gpg command for that - e.g., gpg -eas -r "John Smith" –  gbroiles Aug 6 '13 at 22:08

An alternative for those using msmtp.

cat <<EOF | gpg -ea -r "recipient gpg name" | msmtp -a "account default" recipient@mail.com Subject: Hello Kosmos Type your message here, yada yada yada. EOF


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.