import { useState, useEffect } from 'react' export default function EmailSettings() { const [status, setStatus] = useState(null) const [testTo, setTestTo] = useState('') const [testing, setTesting] = useState(false) const [testMsg, setTestMsg] = useState(null) useEffect(()=>{ const token = localStorage.getItem('bodytrack_token')||'' fetch('/api/admin/email/status',{headers:{'X-Auth-Token':token}}) .then(r=>r.json()).then(setStatus) },[]) const sendTest = async () => { if (!testTo) return setTesting(true); setTestMsg(null) try { const token = localStorage.getItem('bodytrack_token')||'' const r = await fetch('/api/admin/email/test',{ method:'POST',headers:{'Content-Type':'application/json','X-Auth-Token':token}, body:JSON.stringify({to:testTo}) }) if(!r.ok) throw new Error((await r.json()).detail) setTestMsg('✓ Test-E-Mail gesendet!') } catch(e){ setTestMsg('✗ Fehler: '+e.message) } finally{ setTesting(false) } } return (
📧 E-Mail Konfiguration (SMTP)
{!status ?
: ( <>
{status.configured ? <>✓ Konfiguriert: {status.smtp_user} via {status.smtp_host} : <>⚠️ Nicht konfiguriert. SMTP-Einstellungen in der .env Datei setzen.}
{status.configured && ( <>
App-URL: {status.app_url}
Für korrekte Links in E-Mails (z.B. Recovery-Links). In .env als APP_URL setzen.
setTestTo(e.target.value)} style={{flex:1}}/>
{testMsg &&
{testMsg}
} )} {!status.configured && (
Füge folgende Zeilen zur .env Datei hinzu:
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=deine@gmail.com
SMTP_PASS=dein_app_passwort
APP_URL=http://192.168.2.49:3002
)} )}
) }