SHARE
TWEET

Untitled

a guest Oct 4th, 2017 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. import smtplib
  3. import email
  4. from email.mime.text import MIMEText
  5. import random
  6. import os
  7. import sys
  8.  
  9. host = "smtp.example.com"
  10. user = "your_username"
  11. password = "your_password"
  12. default_from = "from@example.com"
  13. indirect_to = "to@somewhere-else.com"
  14.  
  15. def test_message(mto = "tzs@tzs.net", mfrom = default_from):
  16.     tag = str(os.getpid()) + "." + str(random.randint(1, 1000000))
  17.     msg = MIMEText("test message body " + tag)
  18.     msg['Subject'] = "test " + tag
  19.     msg['To'] = mto
  20.     msg['From'] = mfrom
  21.     msg['Date'] = email.utils.formatdate(localtime=True)
  22.     return msg
  23.  
  24. def test25_direct():
  25.     try:
  26.         server = smtplib.SMTP(host, 25)
  27.         server.set_debuglevel(1)
  28.         msg = test_message()
  29.         server.send_message(msg)
  30.         server.quit()
  31.     except:
  32.         print("direct 25 failed:", sys.exc_info()[0])
  33.  
  34. def test25_indirect():
  35.     try:
  36.         server = smtplib.SMTP(host, 25)
  37.         server.set_debuglevel(1)
  38.         msg = test_message(indirect_to)
  39.         server.send_message(msg)
  40.         server.quit()
  41.     except:
  42.         print("indirect 25 failed:", sys.exc_info()[0])
  43.  
  44. def test25_direct_ssl():
  45.     try:
  46.         server = smtplib.SMTP_SSL(host, 465)
  47.         server.set_debuglevel(1)
  48.         server.login(user, password)
  49.         msg = test_message()
  50.         server.send_message(msg)
  51.         server.quit()
  52.     except:
  53.         print("direct 465 SSL failed:", sys.exc_info()[0])
  54.  
  55. def test25_indirect_ssl():
  56.     try:
  57.         server = smtplib.SMTP_SSL(host, 465)
  58.         server.set_debuglevel(1)
  59.         server.login(user, password)
  60.         msg = test_message(indirect_to)
  61.         server.send_message(msg)
  62.         server.quit()
  63.     except:
  64.         print("indirect 465 SSL failed:", sys.exc_info()[0])
  65.  
  66. def test25_direct_starttls():
  67.     try:
  68.         server = smtplib.SMTP(host, 587)
  69.         server.set_debuglevel(1)
  70.         server.starttls()
  71.         server.login(user, password)
  72.         msg = test_message()
  73.         server.send_message(msg)
  74.         server.quit()
  75.     except:
  76.         print("direct 587 STARTTLS failed:", sys.exc_info()[0])
  77.  
  78. def test25_indirect_starttls():
  79.     try:
  80.         server = smtplib.SMTP(host, 587)
  81.         server.set_debuglevel(1)
  82.         server.starttls()
  83.         server.login(user, password)
  84.         msg = test_message(indirect_to)
  85.         server.send_message(msg)
  86.         server.quit()
  87.     except:
  88.         print("indirect 587 STARTTLS failed:", sys.exc_info()[0])
  89.  
  90. #print(test_message())
  91. #test25_direct()
  92. #test25_indirect()
  93. #test25_direct_ssl()
  94. #test25_indirect_ssl()
  95. #test25_direct_starttls()
  96. #test25_indirect_starttls()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top