I'm trying to send manually encrypted S/MIME mails via the exchangelib in Python. I can send simple emails and emails with attachments.
I can also manually S/MIME encrypt data with OpenSSL. I can't seem to find an option for exchangelib to encrypt with S/MIME, so that has to be done manually.
From what I've understood, the easiest way would be to add the appropriate mail headers and encrypt the message body manually for the recipient.
So I believe the headers I have to add are:
MIME-Version: 1.0
Content-Type: application/pkcs7-mime; name="smime.p7m"; smime-type=enveloped-data
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7m"
Content-Description: S/MIME Encrypted Message
The actual mail body would the just be the S/MIME encrypted (base64 encoded) message including optional attachments (e.g. images).
How can I add these custom mail headers with exchangelib in Python?
I've also contacted the developers. More information on the projects Github