如何从Linux命令行自动发送gpg加密邮件?


21

如何从Linux命令行自动发送gpg加密邮件?

我对此有些困惑,我尝试过使用mutt,但是除非以交互方式使用,否则它不会加密邮件。

有谁知道您是否可以使用build in mail命令来执行此操作?

Answers:


25

尝试像

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

通过电子邮件指定收件人行,将文件“文件名”的经过ascii防护的,用公钥加密的副本发送给名为“收件人名”的人(您的gpg密钥环中的人),电子邮件地址为receive@example.com。

要么

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

直接发送文本,而不是从磁盘上的明文文件发送文本。


是否也使用您的私钥在消息上签名?
teeks99 2013年

1
为此,在gpg命令中添加“ s”-例如,gpg -eas -r“ John Smith”
gbroiles 2013年

0

使用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

oil


0

这是我写的一个小脚本。将其保存到〜/ username / bin / gpgmail并运行chmod 755 gpgmail。使用运行gpgmail

#!/bin/bash
# Send encrypted email
# Requires gpg and mail to be setup

echo "Available keys:"
gpg --list-keys
# Gather variables
echo "Enter public key of recipient:"
read user
echo "Enter email:"
read email
echo "Enter subject:"
read subject
echo "Enter message:"
read message

# Pipe the echoed message to gpg, sign and encrypt it to ascii (-eas), include your key so you can read it,
# include recipients key, pipe to mail with the (unencrypted) subject, send to the given email.
echo "$message" | gpg2 --no-emit-version -eas -r galenasphaug@gmail.com -r $user | mail -s "$subject" $email
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.