whisper-tiny-sv / tests /test_email.py
marinone94's picture
Add logic to init env and send email
49a13a3
raw
history blame
1.06 kB
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")