Files
contact-api/app/emailer.py
estebanthi 15d18c3f62
All checks were successful
Build & push Docker image / publish (push) Successful in 30s
initial commit
2025-10-18 16:32:21 +02:00

26 lines
872 B
Python

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}")