import { Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; import { MailTemplate, renderMail } from './mail-templates'; /** * Enqueues transactional mail into the outbox. Actual delivery happens * asynchronously in MailWorker — callers never wait on SMTP. */ @Injectable() export class MailService { constructor(private readonly prisma: PrismaService) {} async enqueue( to: string, template: MailTemplate, params: { displayName: string; link: string }, locale: 'de' | 'en', ): Promise { const rendered = renderMail(template, params, locale); await this.enqueueRaw(to, rendered.subject, rendered.text, rendered.html); } /** Pre-rendered mails (the #95 digests build their own body). */ async enqueueRaw(to: string, subject: string, text: string, html: string): Promise { await this.prisma.mailOutbox.create({ data: { toAddress: to, subject, textBody: text, htmlBody: html }, }); } }