-
-
Save anonymous/b367ac74f346aead27f5811356e3910c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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