0

The following code (based on Python documentation and many articles about MIME messages, convenient subclasses and technical problems) when is executed It shows me that it starts[pic1] but I have to wait forever and again never starts until I kill It.

I will show you my code and I hope to find the solution!

Thanks!

import smtplib
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart

msg = MIMEMultipart('multipart/related')

filename = "C:\.......\asd.png"
f = file(filename, 'rb')
attachment = MIMEImage(f.read(), _subtype="png")
attachment.add_header('Content-Disposition', 'attachment',filename=filename)      

s = smtplib.SMTP('smtp.gmail.com:587')
s.ehlo()
s.starttls()
s.connect('smtp.gmail.com')
s.login('asd@gmail.com','1234')
s.sendmail('asd@gmail.com', 'asd@gmail.com', msg)
s.quit()
  • This is probably not related to the issue, but you never call f.close() – tobspr Oct 20 '15 at 19:58
  • You create a `MIMEImage` but never do anything with it other than adding a header to it. Try `mst.attach(attachment)` to actually attach it to the message. – Colonel Thirty Two Oct 20 '15 at 19:58
  • Look at this http://stackoverflow.com/questions/3362600/how-to-send-email-attachments-with-python – Stafox Oct 20 '15 at 19:59
  • @ColonelThirtyTwo you should probably add the answer as an answer and not as a comment as this is the right answer ... – Ofir Oct 20 '15 at 20:23

0 Answers0