-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathemailsender.py
41 lines (32 loc) · 1.01 KB
/
emailsender.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
38
39
40
41
import json
import smtplib
from logger import Logger
log = Logger()
with open('config.json') as data_file:
config = json.load(data_file)
smtpUsername = config["email"]["smtpUsername"]
smtpPassword = config["email"]["smtpPassword"]
smtpUrl = config["email"]["smtpUrl"]
smtpPort = config["email"].get("smtpPort") # optional
sender = config["email"]["sender"]
recipient = config["email"]["recipient"]
def send_email(message):
email = """From: Lux Med monitor <{}>
To: Szukajacy lekarza {}
Subject: Lux med monitor mowi czesc
Cos sie stalo:
{}
""".format(sender, recipient, message)
msg = {}
msg['Subject'] = 'Test'
msg['From'] = sender
msg['To'] = recipient
try:
server = smtplib.SMTP(host=smtpUrl, port=smtpPort, timeout=5)
server.starttls()
server.set_debuglevel(True)
server.login(smtpUsername, smtpPassword)
server.sendmail(sender, recipient, email)
server.quit()
except Exception as e:
log.warn("Unable to send email. Error was: {}", e)