Advertisement
Guest User

Untitled

a guest
Jun 24th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import smtplib, sys
  2. import traceback
  3. def send_error(sender, recipient, headers, body):
  4.  
  5. SMTP_SERVER = 'smtp.gmail.com'
  6. SMTP_PORT = 587
  7. session = smtplib.SMTP('smtp.gmail.com', 587)
  8. session.ehlo()
  9. session.starttls()
  10. session.ehlo
  11. session.login(sender, 'my password')
  12. send_it = session.sendmail(sender, recipient, headers + "rnrn" + body)
  13. session.quit()
  14. return send_it
  15.  
  16.  
  17. SMTP_SERVER = 'smtp.gmail.com'
  18. SMTP_PORT = 587
  19. sender = 'sender_id@gmail.com'
  20. recipient = 'recipient_id@yahoo.com'
  21. subject = 'report'
  22. body = "Dear Student, n Please send your reportn Thank you for your attention"
  23. open('student.txt', 'w').write(body)
  24.  
  25. headers = ["From: " + sender,
  26. "Subject: " + subject,
  27. "To: " + recipient,
  28. "MIME-Version: 1.0",
  29. "Content-Type: text/html"]
  30. headers = "rn".join(headers)
  31. send_error(sender, recipient, headers, body)
  32.  
  33. import smtplib
  34. from email.mime.text import MIMEText
  35.  
  36. # define content
  37. recipients = ["recipient_id@yahoo.com"]
  38. sender = "sender_id@gmail.com"
  39. subject = "report reminder"
  40. body = """
  41. Dear Student,
  42. Please send your report
  43. Thank you for your attention
  44. """
  45.  
  46. # make up message
  47. msg = MIMEText(body)
  48. msg['Subject'] = subject
  49. msg['From'] = sender
  50. msg['To'] = ", ".join(recipients)
  51.  
  52. # sending
  53. session = smtplib.SMTP('smtp.gmail.com', 587)
  54. session.starttls()
  55. session.login(sender, 'my password')
  56. send_it = session.sendmail(sender, recipients, msg.as_string())
  57. session.quit()
  58.  
  59. "Dear Student, <br> Please send your report<br> Thank you for your attention"
  60.  
  61. "Dear Student, rn Please send your reportrn Thank you for your attention"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement