diff --git a/server/api/members/[id]/send-dues-reminder.post.ts b/server/api/members/[id]/send-dues-reminder.post.ts index 743b54e..eb43ec6 100644 --- a/server/api/members/[id]/send-dues-reminder.post.ts +++ b/server/api/members/[id]/send-dues-reminder.post.ts @@ -46,8 +46,8 @@ export default defineEventHandler(async (event) => { const memberName = member.FullName || `${member.first_name} ${member.last_name}`.trim() || 'Member'; const nextDueDate = getNextDuesDate(member); const membershipFee = `€${registrationConfig.membershipFee}`; - const paymentIban = registrationConfig.iban; - const accountHolder = registrationConfig.accountHolder; + const paymentIban = registrationConfig.iban || ''; + const accountHolder = registrationConfig.accountHolder || ''; const portalUrl = `${process.env.NUXT_PUBLIC_DOMAIN || 'https://monacousa.org'}/dashboard`; const currentYear = new Date().getFullYear(); diff --git a/server/utils/email.ts b/server/utils/email.ts index eb4c191..ca67c3c 100644 --- a/server/utils/email.ts +++ b/server/utils/email.ts @@ -513,3 +513,45 @@ export async function getEmailService(): Promise { 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 { + 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; + } +}