from email.mime.multipart import MIMEMultipart
# Create a multi-part message object msg = MIMEMultipart() # Add text and HTML to the message body text = "Here's some text for the message body." html = "Here's some HTML for the message body.
" msg.attach(MIMEText(text)) msg.attach(MIMEText(html, 'html'))
# Create a MIME object for a PDF attachment pdf_file = open('path/to/file.pdf', 'rb') pdf_attachment = MIMEApplication(pdf_file.read(), _subtype='pdf') pdf_attachment.add_header('Content-Disposition', 'attachment', filename='file.pdf') msg.attach(pdf_attachment) pdf_file.close()Overall, the `email.MIMEMultipart` module is a powerful tool for sending complex email messages with multiple types of content and attachments.