-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendMail.py
27 lines (25 loc) · 831 Bytes
/
SendMail.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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from Constants import *
from Utils import *
def sendEmail ():
# Send the message via local SMTP server.
mail = smtplib.SMTP(PROTOCOL, PORT)
mail.ehlo()
mail.starttls()
mail.login(SENDER, PASSWORD)
for RECEIVER in list(SAMPLE_PAYLOAD.keys()):
msg = MIMEMultipart('alternative')
msg['Subject'] = SUBJECT
msg['From'] = SENDER
new_html = replaceHtml(RECEIVER, SAMPLE_HTML)
html_content = MIMEText(new_html, 'html')
msg.attach(html_content)
msg['To'] = RECEIVER
try:
mail.sendmail(SENDER, RECEIVER, msg.as_string())
print("\nMail sent to "+ RECEIVER)
except:
print ("An error occured.")
mail.quit()