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:
25
src/services/mailer.ts
Normal file
25
src/services/mailer.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user