Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
1,961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #me == my email address
  2. #you == recipient's email address
  3. me = "some.email@gmail.com"
  4. you = "some_email2@gmail.com"
  5.  
  6. # Create message container - the correct MIME type is multipart/alternative.
  7. msg = MIMEMultipart('alternative')
  8. msg['Subject'] = "Alert"
  9. msg['From'] = me
  10. msg['To'] = you
  11.  
  12. # Create the body of the message (a plain-text and an HTML version).
  13. html = '<html><body><p>Hi, I have the following alerts for you!</p></body></html>'
  14.  
  15. # Record the MIME types of both parts - text/plain and text/html.
  16. part2 = MIMEText(html, 'html')
  17.  
  18. # Attach parts into message container.
  19. # According to RFC 2046, the last part of a multipart message, in this case
  20. # the HTML message, is best and preferred.
  21. msg.attach(part2)
  22.  
  23. # Send the message via local SMTP server.
  24. s = smtplib.SMTP('aspmx.l.google.com')
  25. # sendmail function takes 3 arguments: sender's address, recipient's address
  26. # and message to send - here it is sent as one string.
  27. s.sendmail(me, you, msg.as_string())
  28. s.quit()
  29.  
  30. SMTPServerDisconnected: Connection unexpectedly closed
  31.  
  32. retcode (421); Msg: 4.7.0 [ip.octets.listed.here 15] Our system has detected an unusual rate of
  33. 4.7.0 unsolicited mail originating from your IP address. To protect our
  34. 4.7.0 users from spam, mail sent from your IP address has been temporarily
  35. 4.7.0 rate limited. Please visit
  36. 4.7.0 https://support.google.com/mail/answer/81126 to review our Bulk Email
  37. 4.7.0 Senders Guidelines. qa9si9093954wjc.138 - gsmtp
  38.  
  39. # skipped your comments for readability
  40. import smtplib
  41. from email.mime.multipart import MIMEMultipart
  42. from email.mime.text import MIMEText
  43.  
  44. me = "some.email@gmail.com"
  45. my_password = r"your_actual_password"
  46. you = "some.email2@gmail.com"
  47.  
  48. msg = MIMEMultipart('alternative')
  49. msg['Subject'] = "Alert"
  50. msg['From'] = me
  51. msg['To'] = you
  52.  
  53. html = '<html><body><p>Hi, I have the following alerts for you!</p></body></html>'
  54. part2 = MIMEText(html, 'html')
  55.  
  56. msg.attach(part2)
  57.  
  58. # Send the message via gmail's regular server, over SSL - passwords are being sent, afterall
  59. s = smtplib.SMTP_SSL('smtp.gmail.com')
  60. # uncomment if interested in the actual smtp conversation
  61. # s.set_debuglevel(1)
  62. # do the smtp auth; sends ehlo if it hasn't been sent already
  63. s.login(me, my_password)
  64.  
  65. s.sendmail(me, you, msg.as_string())
  66. s.quit()
  67.  
  68. smtplib.SMTP('smtp.gmail.com', 587)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement