Source : https://pastebin.franceserv.fr/1348
Last active
March 25, 2018 21:37
-
-
Save DaffyDuke/e4ad9e216485c7f15dbb6f5833861826 to your computer and use it in GitHub Desktop.
Envoi de mail chiffrés
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# --- Variables definition --------------------------------------- | |
from='noreply@example.com' | |
from_name='Example Compagny' | |
to='example@example.com' | |
to_name='Example Name' | |
subject='Test mail PGP' | |
boundary1=$(openssl rand -hex 24) | |
boundary2=$(openssl rand -hex 24) | |
boundary3=$(openssl rand -hex 24) | |
recipient_id='***key_id***' | |
# --- Message ---------------------------------------------------- | |
message="This is a simple test message which should be encrypted." | |
# --- message format to text/html mode part --------------------------- | |
body_text=$(echo "Content-Type: multipart/mixed; boundary=\"$boundary2\" | |
This is a multi-part message in MIME format. | |
--$boundary2 | |
Content-Type: multipart/alternative; boundary=\"$boundary3\" | |
--$boundary3 | |
Content-Type: text/plain; charset=utf-8 | |
(TEXT mode) Bonjour $to_name, | |
$message | |
Cordialement, | |
$from_name | |
--$boundary3 | |
Content-Type: text/html; charset=utf-8 | |
Content-Language: fr | |
Content-Transfer-Encoding: quoted-printable | |
<html> | |
<body> | |
<p> | |
(HTML mode) Bonjour $to_name, | |
</p><p> | |
$message | |
</p><p> | |
Cordialement,<br/> | |
$from_name | |
</p> | |
</body> | |
</html> | |
--$boundary3-- | |
--$boundary2--" | gpg2 --always-trust -ea -r $recipient_id) | |
# --- mail format global ----------------------------------------- | |
echo "Return-Path: $from | |
From: $from_name <$from> | |
Reply-To: contact@example.com | |
To: $to | |
Subject: $subject | |
MIME-Version: 1.0 | |
Content-Type: multipart/encrypted; protocol=application/pgp-encrypted; boundary=\"$boundary1\" | |
This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) | |
--$boundary1 | |
Content-Type: application/pgp-encrypted | |
Content-Description: PGP/MIME version identification | |
Version: 1 | |
--$boundary1 | |
Content-Type: application/octet-stream; name="encrypted.asc" | |
Content-Description: OpenPGP encrypted message | |
Content-Disposition: inline; filename="encrypted.asc" | |
$body_text | |
--$boundary1--" | /usr/sbin/sendmail -t -oi -f$from |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# --- Variables definition --------------------------------------- | |
from='noreply@example.com' | |
from_name='Example Compagny' | |
to='example@example.com' | |
to_name='Example Name' | |
subject='Test mail PGP' | |
boundary1=$(openssl rand -hex 24) | |
boundary2=$(openssl rand -hex 24) | |
boundary3=$(openssl rand -hex 24) | |
recipient_id='***key_id***' | |
# --- Message ---------------------------------------------------- | |
message="This is a simple test message which should be encrypted." | |
# --- message format to text/html mode part --------------------------- | |
body_text=$(echo "Content-Type: multipart/mixed; boundary=\"$boundary2\" | |
This is a multi-part message in MIME format. | |
--$boundary2 | |
Content-Type: multipart/alternative; boundary=\"$boundary3\" | |
--$boundary3 | |
Content-Type: text/plain; charset=utf-8 | |
(TEXT mode) Bonjour $to_name, | |
$message | |
Cordialement, | |
$from_name | |
--$boundary3 | |
Content-Type: text/html; charset=utf-8 | |
Content-Language: fr | |
Content-Transfer-Encoding: quoted-printable | |
<html> | |
<body> | |
<p> | |
(HTML mode) Bonjour $to_name, | |
</p><p> | |
$message | |
</p><p> | |
Cordialement,<br/> | |
$from_name | |
</p> | |
</body> | |
</html> | |
--$boundary3-- | |
--$boundary2--" | gpg2 --always-trust -ea -r $recipient_id) | |
# --- mail format global ----------------------------------------- | |
echo "Return-Path: $from | |
From: $from_name <$from> | |
Reply-To: contact@example.com | |
To: $to | |
Subject: $subject | |
MIME-Version: 1.0 | |
Content-Type: multipart/encrypted; protocol=application/pgp-encrypted; boundary=\"$boundary1\" | |
This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) | |
--$boundary1 | |
Content-Type: application/pgp-encrypted | |
Content-Description: PGP/MIME version identification | |
Version: 1 | |
--$boundary1 | |
Content-Type: application/octet-stream; name="encrypted.asc" | |
Content-Description: OpenPGP encrypted message | |
Content-Disposition: inline; filename="encrypted.asc" | |
$body_text | |
--$boundary1--" | /usr/sbin/sendmail -t -oi -f$from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment