Files
API/src/common/common.mail.nodemailer.ts
T
Paddy 3c4f3331d8
Jenkins Production Deployment
Add Tickets domain for the voucher-based ticket shop (#8)
Reviewed-on: #8
Co-authored-by: Patrick Mueller <patrick@mueller-patrick.tech>
Co-committed-by: Patrick Mueller <patrick@mueller-patrick.tech>
2026-08-24 21:18:00 +00:00

43 lines
1.3 KiB
TypeScript

import * as nodemailer from 'nodemailer';
export namespace MailService {
const transporter = nodemailer.createTransport({
host: process.env.EMAIL_HOST,
pool: true,
port: 465,
secure: true,
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASSWORD
},
tls: {rejectUnauthorized: false}
});
export interface MailAttachment {
filename: string;
content: string | Buffer;
contentType?: string;
}
export interface SendMailOptions {
html?: string;
attachments?: MailAttachment[];
}
// Builds a fresh options object per call rather than mutating a shared
// module-level one - the transporter is pooled, so overlapping sendMail
// calls (e.g. two guests redeeming at once) previously risked one
// call's recipient/subject/body being overwritten by another's before
// transporter.sendMail() read it.
export const sendMail = async (recipientAddress: string, subject: string, body: string, options?: SendMailOptions) => {
await transporter.sendMail({
from: 'noreply@nachklang.art',
to: recipientAddress,
subject: subject,
text: body,
html: options?.html,
attachments: options?.attachments
});
};
}