Add email backend

This commit is contained in:
Ceda EI 2020-01-19 16:19:55 +05:30
parent ef4ae7942f
commit 432f2854d5
1 changed files with 19 additions and 0 deletions

19
backends/mail.py Normal file
View File

@ -0,0 +1,19 @@
import smtplib
from email.mime.text import MIMEText
def send(config, message):
if config["ssl"]:
smtp = smtplib.SMTP_SSL(config["url"], config["port"])
smtp.starttls()
else:
smtp = smtplib.SMTP(config["url"], config["port"])
if config["tls"]:
smtp.starttls()
msg = MIMEText(message)
msg["Subject"] = "Access to The Long Night"
msg["From"] = config["from"]
msg["To"] = config["tos"]
smtp.login(config["login"], config["password"])
smtp.send_message(msg, from_addr=config["from"], to_addrs=config["tos"])