Skip to content

MIME encryption

A receiving mailserver cannot read encrypted content without the appropriate private keys.

Setup

Prepare your values and Debian packages. CLI tests use only your local test files and configuration.

Import OpenPGP or S/MIME keys into the user's client and select MIME encryption. Do not put users' private keys into the scanner. This local CLI test demonstrates an independent OpenPGP encryption round trip; it does not configure automatic Postfix decryption.

Test

set -euo pipefail
. /root/mailserver.env
export GNUPGHOME=/root/mail-pgp
FPR=$(gpg --with-colons --fingerprint "$MAILBOX" | awk -F: '$1=="fpr" {print $10; exit}')
if ! gpg --with-colons --list-keys "$FPR" | grep -q '^sub:.*:e:'; then
  gpg --batch --pinentry-mode loopback --passphrase-file /root/mail-pgp/passphrase \
    --quick-add-key "$FPR" rsa3072 encr 1y
fi
gpg --batch --yes --trust-model always --recipient "$FPR" \
  --encrypt --output /root/mail-pgp/encrypted.gpg /root/mail-pgp/message.txt
gpg --batch --yes --pinentry-mode loopback --passphrase-file /root/mail-pgp/passphrase \
  --decrypt --output /root/mail-pgp/decrypted.txt /root/mail-pgp/encrypted.gpg
cmp /root/mail-pgp/message.txt /root/mail-pgp/decrypted.txt
echo 'PASS: local encryption/decryption round trip succeeded.'

This CLI test confirms the local behavior described above. For production, send your own message using the actual client and MTA through the real sending route and verify it at a recipient you control.