Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import cgi
  4. from email.MIMEImage import MIMEImage
  5. from email.MIMEMultipart import MIMEMultipart
  6. from email.MIMEText import MIMEText
  7. import mimetypes
  8. import multiprocessing
  9. import os
  10. import smtplib
  11. import sys
  12. import traceback
  13.  
  14. to_addr = "<me>@gmail.com"
  15. from_addr = "<me>@gmail.com"
  16. body_text = "auto email test"
  17. message = MIMEText(body_text)
  18. message["Subject"] = "subject"
  19. message["From"] = from_addr
  20. message["To"] = to_addr
  21. message["Return-Path"] = "<>"
  22. message["Auto-Submitted"] = "auto-generated"
  23. smtp = smtplib.SMTP("localhost")
  24. #smtp = smtplib.SMTP("localhost", 587)
  25. #smtp = smtplib.SMTP("localhost", 666)
  26. #smtp = smtplib.SMTP("localhost", 25)
  27. try:
  28. print("sending email")
  29. smtp.sendmail(from_addr, [to_addr], body_text)
  30. print("sent email")
  31. except Exception, em:
  32. print("ERROR: " + str(em) )
  33. except SMTPException, em:
  34. print("ERROR: " + str(em) )
  35. smtp.quit()
  36.  
  37. root@deb:/****/****/****# python emailer.py
  38. sending email
  39. sent email
  40.  
  41. root@deb:/****/****/****# mailq
  42. 5m 266 1aFMdt-0002d6-KW <>
  43. <me>@gmail.com
  44.  
  45. root@mypc:/****/****/****# python emailer.py
  46. Traceback (most recent call last):
  47. File "emailer.py", line 51, in <module>
  48. smtp = smtplib.SMTP("localhost", 666)
  49. File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
  50. (code, msg) = self.connect(host, port)
  51. File "/usr/lib/python2.7/smtplib.py", line 316, in connect
  52. self.sock = self._get_socket(host, port, self.timeout)
  53. File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
  54. return socket.create_connection((host, port), timeout)
  55. File "/usr/lib/python2.7/socket.py", line 571, in create_connection
  56. raise err
  57. socket.error: [Errno 111] Connection refused
  58.  
  59. 2016-01-02 08:54:49 1aFMdt-0002d6-KW <= <> H=localhost (deb.home) [127.0.0.1] P=esmtp S=266
  60. 2016-01-02 08:56:57 1aFMdt-0002d6-KW gmail-smtp-in.l.google.com [74.125.203.26] Connection timed out
  61. 2016-01-02 08:56:57 1aFMdt-0002d6-KW == <me>@gmail.com R=dnslookup T=remote_smtp defer (110): Connection timed out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement