28 lines
705 B
Python
28 lines
705 B
Python
# pip install python-smail cryptography asn1crypto
|
|
from email.mime.text import MIMEText
|
|
from email.utils import formatdate
|
|
|
|
from smail import sign_message
|
|
|
|
from functions.load_p12_smime import load_p12_smime
|
|
|
|
|
|
def create_signed_email(
|
|
recipient_email: str, subject: str, body: str, config_dict: dict
|
|
):
|
|
|
|
private_key, certificate = load_p12_smime(config_dict=config_dict)
|
|
|
|
message = MIMEText(body)
|
|
message["Date"] = formatdate(localtime=True)
|
|
message["From"] = config_dict["sender_email"]
|
|
message["To"] = recipient_email
|
|
message["Subject"] = subject
|
|
|
|
signed_message = sign_message(
|
|
message,
|
|
private_key,
|
|
certificate,
|
|
)
|
|
|
|
return signed_message
|