I have a Python 3 script that uses MIMEMultipart to send an email with a .xlsx file it has generated attached. I used to use an identical script on Py2 to send the same generated file, the only difference being that the Py2 script collected info from MySQL to create the .xlsx and the Py3 script uses PostgreSQL instead.
msg = MIMEMultipart('alternative')
msg.attach(MIMEText("""HTML stuff""", 'html'))
with open(analysis_file, "rb") as fil:
msg.attach(MIMEApplication(
fil.read(),
Content_Disposition='attachment; filename="%s"' % os.path.basename(analysis_file),
Name=os.path.basename(analysis_file)
))
msg['Subject'] = "SUBJECT"
msg['From']="Me <[email protected]>"
msg['To']= "You <[email protected]>"
server.sendmail(FROMADDR, ["[email protected]"], msg.as_string())
When I switched to the Py3 version of the script, however, the attachment stopped showing up on Microsoft's mail.live. The paperclip symbol that says a message has an attachment still appears, but I can't find it.
--EDIT:
If I set up automatic forwarding to a Gmail account, the .xlsx attachment shows up normally there; however, if I forward it manually it doesn't.
Changing
msg = MIMEMultipart('alternative')
to
msg = MIMEMultipart('html')
fixed it.