Advertisement
Guest User

smtpsend

a guest
Aug 4th, 2016
38,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # -*- coding: utf-8 -*-
  4.  
  5. import smtplib
  6.  
  7. from email.MIMEMultipart import MIMEMultipart
  8.  
  9. from email.MIMEText import MIMEText
  10.  
  11. def checkConnection(server, port, tls, user, passwd):
  12.  
  13. try:
  14.  
  15. connect = smtplib.SMTP(server, port)
  16.  
  17. connect.ehlo()
  18.  
  19. if tls:
  20.  
  21. connect.starttls()
  22.  
  23. connect.ehlo()
  24.  
  25. connect.login(user, passwd)
  26.  
  27. return connect
  28.  
  29. except:
  30.  
  31. return False
  32.  
  33. def inboxEmail(server, port, tls, user, passwd, maillist, From, subject, mailtext):
  34.  
  35. smtpConnect = checkConnection(server, port, tls, user, passwd)
  36.  
  37. emails = len(maillist)
  38.  
  39. for success, sendto in enumerate(maillist):
  40.  
  41. content = MIMEMultipart()
  42.  
  43. content['From'] = From
  44.  
  45. content['To'] = sendto.rstrip()
  46.  
  47. content['Subject'] = subject
  48.  
  49. htmlscript = mailtext.rstrip()
  50.  
  51. content.attach(MIMEText(htmlscript, 'html'))
  52.  
  53. print('Pr0 SMTP Email Sender >>> You are going to send to '+sendto.rstrip())
  54.  
  55. smtpConnect.sendmail(From, sendto.rstrip(), content.as_string())
  56.  
  57. smtpConnect.quit()
  58.  
  59. print('\nBastians Email Sender >>> Email to '+str(success+1)+'/'+str(emails)+' Adresses sended!\n')
  60.  
  61. print"""
  62.  
  63. # _____ __ __ _______ _____ __ __ _ _
  64. # / ____| | \/ | |__ __| | __ \ | \/ | (_) | |
  65. # | (___ | \ / | | | | |__) | | \ / | __ _ _ | | ___ _ __
  66. # \___ \ | |\/| | | | | ___/ | |\/| | / _` | | | | | / _ \ | '__|
  67. # ____) | | | | | | | | | | | | | | (_| | | | | | | __/ | |
  68. # |_____/ |_| |_| |_| |_| |_| |_| \__,_| |_| |_| \___| |_| """
  69.  
  70. print('')
  71.  
  72. smtpServer = raw_input('\nPlease enter the SMTP Server (Hostname or IP Adress): ')
  73.  
  74. smtpPort = input('Please enter the SMTP Port : ')
  75.  
  76. smtpTLS = input('Secure the Email with TLS ? (Yes [1] or No [0]): ')
  77.  
  78. smtpUser = raw_input('Enter the SMTP Username: ')
  79.  
  80. smtpPass = raw_input('Enter the SMTP Password: ')
  81.  
  82. if checkConnection(smtpServer, smtpPort, smtpTLS, smtpUser, smtpPass,):
  83.  
  84. print('\nPr0 SMTP Email Sender >>> SMTP Status // Connected!')
  85.  
  86. sendFrom = raw_input('\nEnter the Receiver: ')
  87.  
  88. sendSubj = raw_input('Enter the Subject: ')
  89.  
  90. userlist = raw_input('Enter the Path of the Email List: ')
  91.  
  92. try:
  93.  
  94. maillist = open(userlist).readlines()
  95.  
  96. print('\n Pr0 SMTP Email Sender >>> I found currently '+str(len(maillist))+' Email Adresses.')
  97.  
  98. htmlscript = raw_input('\nEnter here the Path to your HTML Script: ')
  99.  
  100. try:
  101.  
  102. html = open(htmlscript).read()
  103.  
  104. raw_input('ENTER, to send the HTML Script to '+str(len(maillist))+' ...\n')
  105.  
  106. try:
  107.  
  108. inboxEmail(smtpServer, smtpPort, smtpTLS, smtpUser, smtpPass, maillist, sendFrom, sendSubj, html)
  109.  
  110. except:
  111.  
  112. print('ERROR: I CANT USE THE EMAIL!')
  113.  
  114. except:
  115.  
  116. print('The HTML File cannot get readed yet or is empty.')
  117.  
  118. except:
  119.  
  120. print('The .txt File cannot get readed or is empty.')
  121.  
  122. else:
  123.  
  124. print('I cant connect to the Server :/')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement