initial commit
All checks were successful
Build & push Docker image / publish (push) Successful in 30s
All checks were successful
Build & push Docker image / publish (push) Successful in 30s
This commit is contained in:
25
app/emailer.py
Normal file
25
app/emailer.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import smtplib
|
||||
from email.message import EmailMessage
|
||||
import urllib.request
|
||||
import json
|
||||
|
||||
def send_smtp_email(host: str, port: int, user: str, password: str,
|
||||
mail_from: str, mail_to: str, subject: str, body: str):
|
||||
msg = EmailMessage()
|
||||
msg["From"] = mail_from
|
||||
msg["To"] = mail_to
|
||||
msg["Subject"] = subject
|
||||
msg.set_content(body)
|
||||
|
||||
with smtplib.SMTP(host, port, timeout=10) as s:
|
||||
s.starttls()
|
||||
if user and password:
|
||||
s.login(user, password)
|
||||
s.send_message(msg)
|
||||
|
||||
def send_webhook(url: str, payload: dict):
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
req = urllib.request.Request(url, data=data, headers={"Content-Type": "application/json"})
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
if resp.status >= 300:
|
||||
raise RuntimeError(f"webhook status {resp.status}")
|
||||
Reference in New Issue
Block a user