-
-
Save anonymous/d059c19c3960a283f3b879d670df781b 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 | |
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.login(gmail_sender, gmail_passwd) | |
log.write("Connecting to mail\n") | |
SUBJECT = config.SUBJECT | |
TEXT = config.TEXT | |
i = 1 | |
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 | |
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.login(gmail_sender, gmail_passwd) | |
print("Inside Connecting complete") | |
log.write("Inside Connecting to mail complete\n") | |
TO = email[:17] | |
if i == 900: | |
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) | |
except: | |
print ('error sending mail',TO) | |
log.write("Not graceful up to {}\n".format(TO)) | |
break | |
else: | |
print("until but not",TO) | |
log.write("Finished {} \n".format(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