File size: 1,058 Bytes
49a13a3 |
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 |
import logging
import os
def notify_me(recipient, message=None):
"""
Send an email to the specified address with the specified message
"""
sender = os.environ.get("EMAIL_ADDRESS", None)
password = os.environ.get("EMAIL_PASSWORD", None)
if sender is None:
logging.warning("No email address specified, not sending notification")
if password is None:
logging.warning("No email password specified, not sending notification")
if message is None:
message = "Training is finished!"
if sender is not None:
import smtplib
from email.mime.text import MIMEText
msg = MIMEText(message)
msg["Subject"] = "Training is finished!"
msg["From"] = "marinone.auto@gmail.com"
msg["To"] = recipient
# send the email
smtp_obj = smtplib.SMTP("smtp.gmail.com", 587)
smtp_obj.starttls()
smtp_obj.login(sender, password)
smtp_obj.sendmail(sender, recipient, msg.as_string())
smtp_obj.quit()
notify_me("marinone94@gmail.com") |