24 lines
658 B
Python
24 lines
658 B
Python
import smtplib
|
|
from email.message import EmailMessage
|
|
import logging as log
|
|
from config import cfg
|
|
|
|
def send_mail(text: str) -> None:
|
|
log.info('sending a message')
|
|
msg = EmailMessage()
|
|
msg['Subject'] = cfg.mail.subject
|
|
msg['From'] = cfg.mail.from_address
|
|
msg['To'] = cfg.mail.to_address
|
|
msg.set_content(text)
|
|
try:
|
|
smtp = smtplib.SMTP(cfg.mail.server, cfg.mail.port)
|
|
smtp.starttls()
|
|
smtp.ehlo()
|
|
smtp.login(cfg.mail.user, cfg.mail.pwd)
|
|
|
|
smtp.send_message(msg)
|
|
smtp.quit()
|
|
log.info('message sent successfully')
|
|
except smtplib.SMTPException as err:
|
|
log.warning(err)
|