Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import smtplib
  2. from email.mime.multipart import MIMEMultipart
  3. from email.mime.image import MIMEImage
  4. from email.mime.text import MIMEText
  5.  
  6. sender = "kzabuk@gmail.com"
  7. password_input = raw_input("Vpisi geslo:" )
  8. receiver = "rokzabukovec@hotmail.com"
  9.  
  10. subject = "Python email sending"
  11. text = raw_input("Vpisi sporocilo, ki ga zelis poslati: ")
  12. msg = "From:{0}\nTo:{1}\nSubject:{2}\n\n{3}".format(sender, receiver, subject, text)
  13. print msg
  14.  
  15. msg = MIMEMultipart()
  16. msg['From'] = sender
  17. msg['To'] = receiver
  18. msg['Subject'] = subject
  19.  
  20. image = open("smartninja.jpg", "rb")
  21. msg.attach(MIMEText(text))
  22. msg.attach(MIMEImage(image.read()))
  23. image.close()
  24.  
  25. try:
  26. server = smtplib.SMTP("smtp.gmail.com:587")
  27. server.ehlo()
  28. server.starttls()
  29.  
  30. server.login(user=sender, password=password_input)
  31. server.sendmail(from_addr=sender, to_addrs=receiver, msg=msg.as_string())
  32.  
  33. server.quit()
  34. print "Email was successfully sent to {0}!".format(receiver)
  35. except Exception as e:
  36. print "Error!"
  37. print e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement