I am trying to send a PDF attachment with an email body that summarizes the contents of a PDF file. The body of the email is in both HTML and plain text.
I use the following code to create an email message:
logging.debug(" Building standard email with HTML and Plain Text")
msg = MIMEMultipart("alternative")
msg.attach(MIMEText(email_obj.attachments["plain_text"], "plain", _charset="utf-8"))
msg.attach(MIMEText(email_obj.attachments["html_text"], "html", _charset="utf-8"))
logging.debug(" Adding PDF report")
pdf_part = MIMEApplication(base64.decodestring(email_obj.attachments["pdf_report"]), "pdf")
pdf_part.add_header('Content-Disposition', 'attachment', filename="pdf_report.pdf")
logging.debug(" Attaching PDF report")
msg.attach(pdf_part)
My problem is that my mailbox disappears if I attach the PDF. If I comment on the code that attaches the PDF (Part B), the body of the email will appear.
If I'm wrong, it looks like my PDF attachment is overwriting the body of the email.
source
share