v1.22: Verwaltung sendet Direkt-E-Mails an Mieter mit CC an die Verwaltung

This commit is contained in:
2026-10-04 14:17:12 +02:00
parent 497abfcd4b
commit f15fc6ee0c
10 changed files with 410 additions and 8 deletions
+15 -2
View File
@@ -108,13 +108,17 @@ function buttonHtml(text, url) {
return `<p style="margin:24px 0 0;"><a href="${htmlEscape(url)}" style="display:inline-block;background:${FARBE_BUTTON};color:${FARBE_BUTTON_TEXT};text-decoration:none;font-size:14px;font-weight:700;padding:12px 22px;border-radius:10px;">${htmlEscape(text)}</a></p>`
}
async function sendeMail(an, betreff, text, html) {
async function sendeMail(an, betreff, text, html, cc) {
if (!MAIL_API_URL || !MAIL_API_TOKEN || !an) return
try {
const res = await fetch(`${MAIL_API_URL}/send`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Api-Token': MAIL_API_TOKEN },
body: JSON.stringify({ to: an, subject: betreff, text: `${text}\n\n${FUSSZEILE_TEXT}`, ...(html ? { html } : {}) }),
body: JSON.stringify({
to: an, subject: betreff, text: `${text}\n\n${FUSSZEILE_TEXT}`,
...(html ? { html } : {}),
...(cc ? { cc } : {}), // v1.22: Komma-getrennte CC-Empfänger
}),
})
if (!res.ok) console.warn(`[mail] Versand an ${an} fehlgeschlagen: HTTP ${res.status}`)
} catch (e) {
@@ -122,6 +126,14 @@ async function sendeMail(an, betreff, text, html) {
}
}
/** E-Mail-Adressen aller aktiven Verwaltungsnutzer (komma-getrennt, für CC). */
async function verwaltungEmails() {
const { rows } = await require('./db').pool.query(
`SELECT email FROM users WHERE rolle = 'verwaltung' AND aktiv AND email <> ''`,
)
return rows.map((r) => r.email).join(', ')
}
/** Alle aktiven Verwaltungsnutzer benachrichtigen. */
async function benachrichtigeVerwaltung(betreff, text, html) {
const { rows } = await require('./db').pool.query(
@@ -147,6 +159,7 @@ module.exports = {
sendeMail,
benachrichtigeVerwaltung,
benachrichtigeMieter,
verwaltungEmails,
einheitLabel,
baueHtmlMail,
buttonHtml,