feat: add email notification for new leave requests

- mailer.ts: nodemailer transport via local sendmail
- leave-notification.ts: HTML email matching PHP template
- Sends notification to LEAVE_NOTIFY_EMAIL on new leave request
- Non-blocking: errors logged but don't fail the request
- Added LEAVE_NOTIFY_EMAIL and APP_URL env vars

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-03-23 11:54:29 +01:00
parent 0baa604ade
commit 8a453deaac
5 changed files with 145 additions and 0 deletions

25
src/services/mailer.ts Normal file
View File

@@ -0,0 +1,25 @@
import nodemailer from 'nodemailer';
import { config } from '../config/env';
const transporter = nodemailer.createTransport({
sendmail: true,
newline: 'unix',
path: '/usr/sbin/sendmail',
});
export async function sendMail(to: string, subject: string, html: string): Promise<boolean> {
const from = config.email.smtpFrom || config.email.contactFrom || 'web@boha-automation.cz';
try {
await transporter.sendMail({
from: `System <${from}>`,
to,
subject,
html,
});
return true;
} catch (err) {
console.error(`Mailer error: failed to send to ${to}:`, err);
return false;
}
}