v1.22: Verwaltung sendet Direkt-E-Mails an Mieter mit CC an die Verwaltung
This commit is contained in:
+15
-2
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user