I am using Python 2.7 and trying to send an email using smtplib/MIMEMultipart. I want to send an email that contains multiple pieces e.g., a text message and an html message. I do NOT want them to be alternatives. I want to it to display the text message (inline) follow by the html (inline)
In the future, I would also like to include images. So, the message will contain text, html, and images all inline.
Here is what I have currently, which produces a text message and then the html as an attachment
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
s = smtplib.SMTP('localhost')
#this part works
msg = MIMEMultipart('mixed')
msg['Subject'] = subject
msg['From'] = from
msg['To'] = to
html_str = """<html><head></head><body><p>Test</p></body></html>"""
#this shows up with "This is my text" inline and the html as an attachment
text = MIMEText("This is my text", 'plain')
html = MIMEText(html_str, 'html')
msg.attach(text)
msg.attach(html)
s.sendmail(fromEmail, toEmail, msg.as_string())
s.quit()
How do I add multiple inline pieces to an email? Thank you for your help