I’m using the Microsoft Graph API to retrieve all my emails with attachments and then recreate them using the Python email module. Everything worked fine until I received a signed email. When I try to download a signed email, I’m getting a file with a .p7m extension that contains the signature and attachments. Unfortunately, I have not found a suitable way to process this file in Python and display the email as an original.
Is there a “better way” to handle this case in python?
Creating a not signed email:
message = MIMEMultipart()
body = MIMEText(body, 'html')
message.attach(body)
message['Message-ID'] = email_id
message['Subject'] = subject
message['Date'] = get_standart_format_datetime(received_datetime)
message['From'] = f'{sender} <{email_of_sender}>'
with open(path, 'w') as f:
gen = generator.Generator(f)
gen.flatten(message)