51 Zeilen
2.3 KiB
Python
51 Zeilen
2.3 KiB
Python
"""E-Mail-Versand für Globe Magic Links."""
|
|
import logging
|
|
import aiosmtplib
|
|
from email.mime.text import MIMEText
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
|
from config import SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_FROM_EMAIL, SMTP_FROM_NAME
|
|
|
|
logger = logging.getLogger("globe.email")
|
|
|
|
|
|
async def send_magic_link_email(to_email: str, link: str):
|
|
"""Sendet Magic Link per E-Mail."""
|
|
html = f"""
|
|
<div style="font-family: 'Courier New', monospace; max-width: 500px; margin: 0 auto; padding: 30px; background: #0b1121; color: #e8eaf0; border-radius: 12px;">
|
|
<h2 style="color: #00ff88; font-size: 16px; letter-spacing: 2px; margin-bottom: 24px;">AEGISSIGHT GLOBE</h2>
|
|
<p style="font-size: 14px; line-height: 1.6;">Klicke auf den Button, um dich anzumelden:</p>
|
|
<div style="text-align: center; margin: 24px 0;">
|
|
<a href="{link}" style="display: inline-block; background: #00ff88; color: #0b1121; padding: 14px 40px; border-radius: 6px; text-decoration: none; font-weight: 700; font-size: 16px; letter-spacing: 1px;">Jetzt anmelden</a>
|
|
</div>
|
|
<p style="font-size: 12px; color: rgba(255,255,255,0.4); line-height: 1.6;">
|
|
Oder kopiere diesen Link in deinen Browser:<br>
|
|
<a href="{link}" style="color: #00ff88; word-break: break-all; font-size: 11px;">{link}</a>
|
|
</p>
|
|
<p style="font-size: 11px; color: rgba(255,255,255,0.3); margin-top: 24px;">
|
|
Dieser Link ist 10 Minuten gültig. Falls du diese Anfrage nicht gesendet hast, ignoriere diese E-Mail.
|
|
</p>
|
|
</div>
|
|
"""
|
|
|
|
msg = MIMEMultipart("alternative")
|
|
msg["From"] = f"{SMTP_FROM_NAME} <{SMTP_FROM_EMAIL}>"
|
|
msg["To"] = to_email
|
|
msg["Subject"] = "AegisSight Globe — Anmelde-Link"
|
|
msg.attach(MIMEText(f"Dein Globe-Anmeldelink:\n\n{link}\n\nGültig für 10 Minuten.", "plain"))
|
|
msg.attach(MIMEText(html, "html"))
|
|
|
|
try:
|
|
await aiosmtplib.send(
|
|
msg,
|
|
hostname=SMTP_HOST,
|
|
port=SMTP_PORT,
|
|
username=SMTP_USER,
|
|
password=SMTP_PASSWORD,
|
|
start_tls=True,
|
|
)
|
|
logger.info(f"Magic Link E-Mail gesendet an {to_email}")
|
|
except Exception as e:
|
|
logger.error(f"E-Mail-Versand fehlgeschlagen: {e}")
|
|
raise
|