'use server' import nodemailer from 'nodemailer' interface EmailParams { to: string | string[] cc?: string | string[] subject: string content: string } export async function sendEmail({ to, cc, subject, content }: EmailParams): Promise { // Create a transporter using SMTP const transporter = nodemailer.createTransport({ host: process.env.SMTP_HOST, port: Number(process.env.SMTP_PORT), secure: process.env.SMTP_SECURE === 'true', requireTLS: true, auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASSWORD, }, }) // Email options const mailOptions = { from: process.env.SMTP_USER, to: Array.isArray(to) ? to.join(', ') : to, cc: cc ? (Array.isArray(cc) ? cc.join(', ') : cc) : undefined, subject, html: content, } try { // Send email await transporter.sendMail(mailOptions) } catch (error) { console.error('Error sending email:', error) throw new Error('Failed to send email') } } async function sendEmailTest() { await sendEmail({ to: 'test@test.com', cc: 'test2@test.com', subject: 'Test Email', content: '

Hello

This is a test email.

', }) }