fixes
All checks were successful
Build And Push Image / docker (push) Successful in 1m31s

This commit is contained in:
2025-08-15 14:52:18 +02:00
parent a8022d8fb3
commit df6d549573
2 changed files with 44 additions and 2 deletions

View File

@@ -513,3 +513,45 @@ export async function getEmailService(): Promise<EmailService> {
export function createEmailService(config: SMTPConfig): EmailService {
return new EmailService(config);
}
/**
* Generic send email function for custom templates
*/
export async function sendEmail(options: {
to: string;
subject: string;
template: string;
data: any;
}): Promise<void> {
try {
const emailService = await getEmailService();
// Get the template
const templateFunction = (emailService as any).getTemplate(options.template);
if (!templateFunction) {
throw new Error(`Email template '${options.template}' not found`);
}
// Add common template data
const templateData = {
...options.data,
logoUrl: options.data.logoUrl || 'https://portal.monacousa.org/MONACOUSA-Flags_376x376.png',
baseUrl: process.env.NUXT_PUBLIC_DOMAIN || 'https://portal.monacousa.org'
};
// Compile template with data
const html = templateFunction(templateData);
// Send email using the private sendEmail method
await (emailService as any).sendEmail({
to: options.to,
subject: options.subject,
html
});
console.log(`[sendEmail] ✅ Email sent successfully to ${options.to} using template '${options.template}'`);
} catch (error) {
console.error(`[sendEmail] ❌ Failed to send email to ${options.to}:`, error);
throw error;
}
}