I have mHTML document created another programm and I want send it using Python. But I can only send text from mHTML document without formatting. Have any ideas how send text with formatting from mHTML?
Here’s my code:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.message import MIMEMessage
import datetime
import logging logger =logging.getLogger(__name__)
sender = "###"
smtpServerName = '###'
def sendEmail(subject, text, addressee):
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = addressee
text = MIMEText(text, 'html')
msg.attach(text)
smtpServer = smtplib.SMTP(smtpServerName)
logger.info('Sending email to: ' + addressee + ' with subject: ' + subject)
smtpServer.sendmail(sender, addressee.split(","), msg.as_string())
smtpServer.quit()
text = open('mHTML_doc.mhtml')
sendEmail('Hello!', text.read(), "###")
smtp_server = "###"
smtp_port = 25
smtp_user = "###"
smtp_pwd = "" smtp = smtplib.SMTP(smtp_server, smtp_port)