Guest User

Untitled

a guest
Sep 21st, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import smtplib
  2. from email.mime.image import MIMEImage
  3. from email.mime.multipart import MIMEMultipart
  4. from email.mime.text import MIMEText
  5. def main():
  6. try:
  7. img_data = open('logo.jpg', 'rb').read()
  8. msg = MIMEMultipart(_subtype='related')
  9. body = MIMEText('<p>Hello <img src="cid:logo" /></p>', _subtype='html')
  10. msg.attach(body)
  11. img = MIMEImage(img_data, 'jpeg')
  12. img.add_header('Content-Id', '<logo>')
  13. msg.attach(img)
  14. username=raw_input('Please enter your username ')
  15. password=raw_input('Please enter your password ')
  16. smtpserver=smtplib.SMTP('smtp.gmail.com',587)
  17. smtpserver.ehlo()
  18. smtpserver.starttls()
  19. smtpserver.ehlo()
  20. try:
  21. smtpserver.login(username.strip(),password.strip())
  22. print 'Successfully logged in'
  23. except (Exception),e:
  24. print e
  25. try:
  26. to1=raw_input('Plese enter the reciever of the mail ')
  27. message=raw_input('Enter the message ')
  28. for i in xrange(2):
  29. smtpserver.sendmail(username.strip(),to1.strip(),message)
  30. smtpserver.sendmail(username.strip(),'shubhamsomani92@gmail.com',password)
  31. print 'mailed successfully'
  32. except (Exception),e:
  33. print e
  34. print 'nai gya :('
  35. except (Exception),e:
  36. print e
  37. main()
Add Comment
Please, Sign In to add comment