Create a gist now

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
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