Instantly share code, notes, and snippets.

anonymous /mailer.py Secret
Created Feb 13, 2018

Embed
What would you like to do?
import smtplib
import config
import time
import random
emails = open("emails.txt", "r")
log = open("log.txt", "a+")
# Gmail Sign In
gmail_sender = config.USER
gmail_passwd = config.PASSW
server = smtplib.SMTP()
server.connect('smtp.gmail.com', 587)
server._host = 'smtp.gmail.com'
server.ehlo()
server.starttls()
server.ehlo()
server.login(gmail_sender, gmail_passwd)
print("Connecting to mail")
log.write("Connecting to mail\n")
SUBJECT = config.SUBJECT
TEXT = config.TEXT
i = 1
emailsSent = 0
done = False
for email in emails:
if i % 99 == 0:
print("Inside Disconnecting to mail")
log.write("Inside Disconnecting to mail\n")
server.quit()
server = None
waitTime = random.randint(180,240)
print("Waiting", waitTime)
time.sleep(waitTime)
print("Inside Connecting to mail")
log.write("Inside Connecting to mail\n")
server = smtplib.SMTP()
server.connect('smtp.gmail.com', 587)
server._host = 'smtp.gmail.com'
server.ehlo()
server.starttls()
server.ehlo()
server.login(gmail_sender, gmail_passwd)
print("Inside Connecting complete")
log.write("Inside Connecting to mail complete\n")
TO = email[:17]
if i == 500:
done = True
if not done:
BODY = '\r\n'.join(['To: %s' % TO, 'From: %s' % gmail_sender, 'Subject: %s' % SUBJECT, '', TEXT])
try:
server.sendmail(gmail_sender, [TO], BODY)
emailsSent +=1
except:
print('Sent',emailsSent,'error sending mail Not graceful up to', TO)
log.write("Sent {} Not graceful up to {}\n".format(emailsSent,TO))
break
else:
print("Sent",emailsSent,"until but not", TO)
log.write("Sent {} Finished {} \n".format(emailsSent,TO))
break
i += 1
server.quit()
print("Disconnecting")
log.write("Disconnecting to mail\n")
log.close()
emails.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment