mogaal / sendemail

lightweight, command line SMTP email client
http://www.caspian.dotconf.net/menu/Software/SendEmail/
223 stars 75 forks source link

can sendemail support PGP encryption? #8

Open fredzannarbor opened 7 years ago

fredzannarbor commented 7 years ago

I would like to be able to send PGP-encrypted messages from sendemail.

JayBrown commented 7 years ago

I have a similar problem, in that I want to send S/MIME-encrypted emails.

I don't think sendEmail includes GPG (and S/MIME) encryption directly, but if you have installed gpg, then you can encrypt the message before sending it, as you can encrypt messages with openssl.

The question is how to send a message like this (GPG or S/MIME) in a way that GUI-based email clients that receive the encrypted email, will decrypt it automatically. You have to tell the receiving client somehow that the message it has received, is encrypted in a certain way. I assume it is done by way of an attachment, but I can't say for sure.

JayBrown commented 7 years ago

I haven't gotten S/MIME encryption to work yet, but GPG works fine. On macOS I've succeed like this:

echo "$BODY" \
    | /usr/local/bin/gpg2 --no-emit-version -ea \
    -r "$RECIPIENT" \
    | /usr/local/bin/sendEmail -o message-content-type=auto -o tls=yes \
    -f "$SENDER" -t "$RECIPIENT" -u "$SUBJECT" \
    -s "$SERVER:$PORT" -xu "$ACCOUNT" -xp "$PASSWORD"

You can also use -eas instead of -ea, if you want to sign your message in addition to encryption. To also encrypt it with your sender GPG key, add -r "$SENDER".

Screengrab:

GUI inbox

LivInTheLookingGlass commented 7 years ago

The problem with the above is that it doesn't do it in the standard way. It appears to interpret this as an attachment. So while a properly supported client will send:

Content-Type: multipart/encrypted;
    protocol="application/pgp-encrypted";
    boundary="1502587644/711247/181064/dobby21a"

 This is a MIME-encapsulated message.

--1502587644/711247/181064/dobby21a
Content-Type: application/pgp-encrypted
Content-Disposition: attachment

Version: 1

--1502587644/711247/181064/dobby21a
Content-Type: application/octet-stream
Content-Disposition: inline; filename="msg.asc"

-----BEGIN PGP MESSAGE-----
Version: GnuPG v2

hQIMA/U6ycjNkCBGAQ//bZaT7rNxhGM7sQ5ScGlX6K3BcSWSzPTTe3zvbWKsOybr
nZcCPMS9x/anUYrp5mLt2vksk3jkH0DuxCSmUQDp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ziw1FJBGXrN03SCZ1w4xMLjRMN1cwud75l7QXP9x27l
1FMDibZ0m6x/RF42Nwo0UcF8i5bVbzUa/xn4aPyC1k4GOX3Ag8tHdZ9gdDI6FL+V
MNQqQHI4T8J/up1qtpJ9Q9QIxwaXI6BSBKDYTG1RRGGETS3USbEin63i1FFw6KFB
/DEHJYvkk9noUwMPYBEbhnGkJYXbWGs//BFBgnRMc3o+IMX7ncHkZeEmdFxXM+JB
40pYJ1O6lqsXYa6jkJJyvjzR
=DIrK
-----END PGP MESSAGE-----

--1502587644/711247/181064/dobby21a--

This appears to send:

Content-Type: multipart/related; boundary="----MIME delimiter for sendEmail-21628.2369374348"

 This is a multi-part message in MIME format. To properly display this message you need a MIME-Version 1.0 compliant Email program.

------MIME delimiter for sendEmail-21628.2369374348
Content-Type: application/pgp-encrypted;
        charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

-----BEGIN PGP MESSAGE-----

hQIMA/U6ycjNkCBGARAAhv2Po7nIcvMhUcdPvqjJJwTnZ5FtrGp5A4DRqixHOuRy
p2tIwDVK4F1C8vFGD5ABdR8PylDd+teoMCshkeGfQHNamdfmlIRPY0qPDv5RqfDG
WPtQeATdtssbZeYY1W6soQYY80x2XfF800/a9h4KORClwunVAHGaGGAQ+8XmefOg
e6nbJzlEZXxv+ltNf3OZ7GDeimDeRtaaYW5exIBIy0tNN4o55egJH6C0ouAGrIdG
Fa8F5BzeD5FaDKRtoWutLdLsU9gDuoJzQAkDh/L5LSe38LVSM8kvQxo7O/E3zKAk
A6EODnyk0vo9diTYTjNp/QZs+4Logm+HEuj6aIQQUzAtg16q5fMT/pcsjiP4NREp
W9My2RDqFiYatFG3efRvMTGbYVaLRV6sG11O+vncuaFPadVPwV1Esa9ZyPF2KFk8
pYy4ER7u0h+GhG0PRJ+acqvUTdD5dod8bzkjU6bpAb3+hC9mND/jPMQNUox1b8EM
zHKM/AOZT44AAsnspt30rfXscovUEvKVFSM7Ac1UA39lld2t6f9jQaF8/cEhorpz
z3bvr/Y4HX1Uy/2q5/BkSrrPGm3Rbd+LiIiVykpifnQJmZqyc5OZJ9CF3bH893Ix
U4/1VHv5t2GwCAXgiq3QeqpUbmLPll9HjQL9+cqSQ1IxiDaDgEZEPjwEO76HhL/S
wLsB/7rMeLOI6ebl4sorJhfwFGt94V3ON3XzK4Ka3HvjX0z+7hTN/a3Mzgx8q9wB
RdzoYBpa7F59ctEV6WZ2F6mQl5Jxt7MrJ68yRQnH12THwFeI2nklQgsIvgS/KiXR
2RQ0SoN5m1VCj4DxBXV8bq9pxLqPSQCw+IVDpBAkuvt42MKnsrgD1ecoSTF104Sd
fkflwDLJuh7GK0HkDEUkprNwvvs/j2ZtYByK1Qsk1Oj653Cf/ov7ZFxRj33UdVZz
SBv7uc6H1HjFc5TG/yV29GNh/LH7TYRuVyqRpl7G0Y6lulj3sr8tnyLuyH3uLgIq
SxHzYu0lrD/JvkBrOB2B+cb+EvxMkaezjKMQmqHGaKqdYenrgD3gxmEzDa/2D5tX
QFmBBfF/2JkX9rCf55yG/QwVWYh7C2kBPcglHG0/hayvAtUFvM8eWtsXmR/8nEOE
ErmPtdrDJpo7BTQX0EjjJ2DvqLQ9aUhfFboO0DJhMukvTRRhaoD8Gh1Vfg56
=uHYs
-----END PGP MESSAGE-----

------MIME delimiter for sendEmail-21628.2369374348--

I'm not sure I understand the difference, but I do know it's enough that neither KMail nor K-9 Mail can understand that it's a PGP style message. They interpret it as an attachment instead.

The command I used was:

echo $BODY | gpg2 -eas -r "$TO" | sendemail -f "$FROM" -t "$TO" -s $SERVER -xu $FROM -xp "$PASS" -o tls=yes -o message-content-type=application/pgp-encrypted
anishnath commented 8 months ago

Used https://8gwifi.org/pgpencdec.jsp for PGP encryption/decryption in the lab enviroment to understand what this tech is all about