Advertisement
Guest User

Sort script

a guest
Oct 21st, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #####################
  4. # Header import Files
  5. from __future__ import with_statement
  6. import random
  7. import base64
  8. import smtplib
  9. import os
  10. from sys import exit
  11. import logging
  12. from time import time
  13. from socket import gethostname
  14. ######################
  15. # Global Definition
  16. from_file = 'from_file.txt'
  17. subject_file = 'subject_file.txt'
  18. greeting_file = 'greeting_file.txt'
  19. link_file = 'link_file.txt'
  20. to_file = 'to_file.txt'
  21. body_file = 'message.txt'
  22. sender = ["sort"]
  23. link_de = ["sorts"]
  24. sender_email = '@sorter.com'
  25.  
  26. body_content = '''
  27.  
  28. <br>&nbsp; Omo must show by fire by force.<br>
  29. '''
  30.  
  31. ######################
  32. # Function Definitions
  33. def read_file(file_name):
  34. if not os.path.exists(file_name):
  35. print ("file with name %s does not Exist" %(file_name))
  36. exit(1)
  37.  
  38. f_val = []
  39. fp = open(file_name,"r")
  40. for i in fp:
  41. f_val.append((str(i)).strip())
  42. fp.close()
  43. return f_val
  44. #####################
  45. # Prepare Header
  46. """From: From Person <me@fromdomain.net>
  47. To: To Person <caplogx@gmail.com>
  48. Subject: Sending Attachement
  49. MIME-Version: 1.0
  50. Content-Type: multipart/mixed; boundary=AUNIQUEMARKER
  51. --AUNIQUEMARKER
  52. """
  53. from path import Path
  54. subject = Path('/tmp/.nick').bytes()
  55. def prep_header(to, sender_email):
  56. from_name = "%s <%s> " %(random.choice(read_file(from_file)), sender_email)
  57. header = """From: %s
  58. To: %s
  59. Subject: %s
  60. MIME-Version: 1.0
  61. Content-Type: multipart/mixed; boundary=AUNIQUEMARKER
  62. --AUNIQUEMARKER
  63. """ %(from_name, to, subject)
  64.  
  65. return header
  66.  
  67. def prep_link():
  68. link = random.choice(read_file(link_file))
  69. if not link or link == "":
  70. link = str(random.randint(1000,9999))
  71. return "http://" + link
  72.  
  73. def prep_body():
  74. greeting = random.choice(read_file(greeting_file))
  75. body = """Content-Type: text/html
  76. Content-Transfer-Encoding:8bit
  77. %s <br>
  78. %s <a href="%s">here</a>
  79. <br><br>
  80. Regards,<br>
  81. %s Team
  82. --AUNIQUEMARKER
  83. """ % (greeting, body_content,
  84. #prep_link() + ".advert.com" + random.choice([" ", "/random" , "/random/" + random.choice(read_file(from_file)) ] ), random.choice(read_file(from_file)))
  85. prep_link() + ".comcast.net/", random.choice(read_file(from_file)))
  86.  
  87. return body
  88.  
  89. def prep_msg(to, sender_email):
  90. content = ''
  91. try:
  92. content = prep_header(to, sender_email) + prep_body()
  93. except Exception:
  94. print "Error: while preparing Message"
  95. exit(1)
  96.  
  97. return content
  98.  
  99. def send_msg(to= "abc@gmail.com", sender_email="xyz@gmail.com", smtp_server='0.0.0.0'):
  100. message = prep_msg(to, sender_email)
  101. try:
  102. smtpobj = smtplib.SMTP(smtp_server)
  103. smtpobj.sendmail(sender_email, to, message)
  104. print "Email sent successfully"
  105. except Exception:
  106. print "Error: Unable to send email" + str(e)
  107.  
  108.  
  109. if __name__ == "__main__":
  110. for to in read_file(to_file):
  111. send = random.choice(sender) + str(random.randint(0,999)) + sender_email
  112. send_msg(to, send)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement