Guest User

Untitled

a guest
Sep 3rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import os
  4. import smtplib
  5. from email.mime.text import MIMEText
  6. from email.mime.multipart import MIMEMultipart
  7. from email.mime.base import MIMEBase
  8. from email import encoders
  9.  
  10. email_user = 'testing04032016@gmail.com'
  11. email_password = 'Testing@0403'
  12. email_send = 'rajjnagar@gmail.com'
  13.  
  14. subject = 'testtting'
  15.  
  16. msg = MIMEMultipart()
  17. msg['From'] = email_user
  18. msg['To'] = email_send
  19. msg['Subject'] = subject
  20.  
  21. body = 'Hi there, sending this email from Python!'
  22. msg.attach(MIMEText(body,'plain'))
  23.  
  24. filename = "C:\\Users\\lvura_000\\Downloads\\maxresdefault.jpg"
  25. attachment = open(filename,'rb')
  26. name=os.path.basename(filename)
  27.  
  28. part = MIMEBase('application','octet-stream')
  29. part.set_payload((attachment).read())
  30. encoders.encode_base64(part)
  31. part.add_header('Content-Disposition',"attachment; filename= "+name)
  32.  
  33. msg.attach(part)
  34. text = msg.as_string()
  35. try:
  36. server = smtplib.SMTP('smtp.gmail.com',587)
  37. server.starttls()
  38. server.login(email_user,email_password)
  39. server.sendmail(email_user,email_send,text)
  40. print ("Successfully sent email")
  41. server.quit()
  42. except SMTPException:
  43. print ("Error: unable to send email")
Add Comment
Please, Sign In to add comment