forked from AllinoneCyberteam/Mass-email-sender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.py
37 lines (30 loc) · 897 Bytes
/
mailer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
""" Bulk mailer script """
import json
import smtplib
import time
EMAIL_LIST = []
# Read config file
with open("./CONFIG", "r") as file:
CONFIG = json.loads(file.read())
file.close()
# Read mailing list and add it to EMAIL_LIST
with open("./mailing_list.txt", "r") as file:
while True:
LINE = file.readline()
if not LINE:
break
else:
EMAIL_LIST.append(LINE.strip())
file.close()
# Construct the message to be sent.
MESSAGE = "SUBJECT: {} \n\n{}".format(CONFIG["subject"], CONFIG["message"])
# Open SMTP secure connection.
EMAIL_SERVER = smtplib.SMTP_SSL("smtp.gmail.com", "465")
# Login
EMAIL_SERVER.login(CONFIG["email"], CONFIG["password"])
# Send emails to emails in EMAIL_LIST in a loop
for email in EMAIL_LIST:
EMAIL_SERVER.sendmail(CONFIG["email"], email, MESSAGE)
time.sleep(0.5)
# Quit SMTP server
EMAIL_SERVER.quit()