Closed ghost closed 5 years ago
Like kinda like this.
objMsg = MIMEMultipart()
objMsg["Subject"] = "SUBJECT"
filename = "text.doc"
f = file(filename)
attachment = MIMEText(f.read())
attachment.add_header('Content-Disposition', 'attachment', filename=filename)
objMsg.attach(attachment)
SmtpServer = smtplib.SMTP_SSL("smtp.gmail.com", 465); SmtpServer.ehlo()
SmtpServer.login(strEmailAc, strEmailPass)
SmtpServer.sendmail(strEmailAc, strEmailAc, objMsg.as_string())
SmtpServer.close()
Corrupted doc attachment. Can't open it And Thanks for prompt reply.
You probably have to add, f.close()
after the attachment = MIMEText(f.read())
.
Also make sure you are using correct path.
Again same error i think that the file cannot be opened in text format. any other way to send it Thanks in advance
Maybe try opening file as byte. So f = file(filename, "rb")
It's almost resolve but the attachment is still corrupted. Instead the body of the email contain the matter present in .doc file
But it comes with lot of residue. Thanks in advance
https://stackoverflow.com/questions/11921188/how-to-send-email-with-pdf-attachment-in-python
Here is how. Should work with doc.
Thanks, Solved
OS: [e.g. Windows 10] Commit/Build: [e.g. b227928]
I am trying to mail .doc files but as i m new to python, can't figure the way out. Kindly guide me.........