46 lines
996 B
TypeScript
46 lines
996 B
TypeScript
/**
|
|
* Email utility using AWS SES SMTP
|
|
*/
|
|
|
|
import nodemailer from 'nodemailer';
|
|
|
|
// Create reusable transporter
|
|
const transporter = nodemailer.createTransport({
|
|
host: process.env.SMTP_HOST,
|
|
port: parseInt(process.env.SMTP_PORT || '587'),
|
|
secure: false, // Use STARTTLS
|
|
auth: {
|
|
user: process.env.SMTP_USERNAME,
|
|
pass: process.env.SMTP_PASSWORD
|
|
}
|
|
});
|
|
|
|
interface EmailOptions {
|
|
to: string;
|
|
subject: string;
|
|
html: string;
|
|
from?: string;
|
|
}
|
|
|
|
/**
|
|
* Send an email via AWS SES
|
|
*/
|
|
export async function sendEmail(options: EmailOptions) {
|
|
const from = options.from || process.env.FROM_EMAIL || 'noreply@viralguru.app';
|
|
|
|
try {
|
|
const info = await transporter.sendMail({
|
|
from,
|
|
to: options.to,
|
|
subject: options.subject,
|
|
html: options.html
|
|
});
|
|
|
|
console.log('Email sent:', info.messageId);
|
|
return { success: true, messageId: info.messageId };
|
|
} catch (error) {
|
|
console.error('Email send failed:', error);
|
|
throw error;
|
|
}
|
|
}
|