Advertisement
Guest User

Untitled

a guest
Jun 19th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. import smtplib
  2.  
  3. server = smtplib.SMTP('smtp.gmail.com', 587)
  4. server.ehlo()
  5. server.starttls()
  6. server.login("mymail@gmail.com", "mypassword")
  7.  
  8. msg = "Hello world"
  9. server.sendmail("mymail@gmail.com", "mymail@gmail.com", msg)
  10. server.quit()
  11.  
  12. server.login("user@gmail.com", "psw")
  13.  
  14. File "C:Pythonlibsmtplib.py", line 652, in login
  15.  
  16. raise SMTPAuthenticationError(code, resp)
  17.  
  18. smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuxbn5.7.14 4i2u8qU8V3jgf6uGv8da1RAGPJyctRvIFy_kjai6aKVx_B6qVhoz_dzFpvfPC18H-jeM6Kn5.7.14 cnm2HVuq-wr-uw59hD31ms-cxMmnZuq6Z3_liDaDmu8_UqaiUwR4FUiuX2i5pPdQjJzFvvn5.7.14 4VrEF5XT4ol2iN17gnB_jITpwzsjH9Ox3NCNcfl7SriHr5m7esc15PWI0CG_2CTlyh7RxWn5.7.14 XhoJPajs8GMd-khOQWUqucywfrfo> Please log in via your web browser andn5.7.14 then try again.n5.7.14 Learn more atn5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 ef10sm13614207wjd.49 - gsmtp')
  19.  
  20. import smtplib
  21.  
  22. session = smtplib.SMTP('smtp.gmail.com', 587)
  23. session.ehlo()
  24. session.starttls()
  25. session.login('youremail@gmail.com',' password')
  26. headers = "rn".join(["from: " + 'youremail@gmail.com',
  27. "subject: " + "test",
  28. "to: " + 'contactemail@gmail.com',
  29. "mime-version: 1.0",
  30. "content-type: text/html"])
  31.  
  32. # body_of_email can be plaintext or html!
  33. content = headers + "rnrn" + "body_of_email"
  34. session.sendmail('youremail@gmail.com', 'contactemail@gmail.com', content)
  35.  
  36. import requests
  37.  
  38. def send_simple_message(target):
  39. return requests.post(
  40. "https://api.mailgun.net/v3/samples.mailgun.org/messages",
  41. auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
  42. data={"from": "Excited User <excited@samples.mailgun.org>",
  43. "to": [target],
  44. "subject": "Hello",
  45. "text": "Testing some Mailgun awesomeness!"})
  46.  
  47. send_simple_message('target@email.com')
  48.  
  49. import yagmail
  50. yag = yagmail.SMTP('user', 'pw')
  51. yag.send(contents = msg)
  52.  
  53. contents = ['Body text, and here is an embedded image:', 'http://somedomain/image.png',
  54. 'You can also find an audio file attached.', '/local/path/song.mp3']
  55.  
  56. import yagmail
  57. yagmail.SMTP().send(contents = contents)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement