-
Notifications
You must be signed in to change notification settings - Fork 1
/
smtp.py
32 lines (25 loc) · 790 Bytes
/
smtp.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
import smtplib
import config
import logging
# Import the email modules we'll need
from email.mime.text import MIMEText
logger = logging.getLogger('zmchecker.smtp')
def sendemail(text,subject):
msg = MIMEText(text)
msg['From'] = config.email_from
msg['To'] = config.email_to
msg['Subject'] = subject
try:
if config.smtp_password == 587:
server = smtplib.SMTP(config.smtp_server, config.smtp_port)
server.starttls()
else:
server = smtplib.SMTP(config.smtp_server)
if config.smtp_password != "":
server.login(config.email_login, config.smtp_password)
server.send_message(msg)
server.quit()
print("Email Sent! %s" % text)
logger.info("Sent email %s" % text)
except:
logger.error("Couldn't send email %s" % msg)