Files
nlcc-itinerary/server/utils/email.ts

123 lines
4.1 KiB
TypeScript

import nodemailer from 'nodemailer'
export async function sendPasswordResetEmail(email: string, code: string) {
const config = useRuntimeConfig()
const transporter = nodemailer.createTransport({
host: config.emailHost,
port: parseInt(config.emailPort),
secure: parseInt(config.emailPort) === 465,
auth: {
user: config.emailUser,
pass: config.emailPassword,
},
})
const mailOptions = {
from: config.emailFrom,
to: email,
subject: 'Password Reset Code - New Life Christian Church',
text: `Please enter this 6 digit code to reset your password for the New Life Christian Church sermon page: ${code}`,
html: `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<h2 style="color: #333;">Password Reset Request</h2>
<p>Please enter this 6 digit code to reset your password for the New Life Christian Church sermon page:</p>
<div style="background-color: #f4f4f4; padding: 20px; text-align: center; font-size: 32px; font-weight: bold; letter-spacing: 5px; margin: 20px 0;">
${code}
</div>
<p style="color: #666;">This code will expire in 15 minutes.</p>
<p style="color: #666;">If you did not request a password reset, please ignore this email.</p>
</div>
`,
}
await transporter.sendMail(mailOptions)
}
export function generateResetCode(): string {
return Math.floor(100000 + Math.random() * 900000).toString()
}
export async function sendSermonNotesEmail(
email: string,
firstName: string,
sermonTitle: string,
sermonDate: string,
bibleReferences: string,
personalAppliance: string,
pastorsChallenge: string,
userNotes: string
) {
const config = useRuntimeConfig()
const transporter = nodemailer.createTransport({
host: config.emailHost,
port: parseInt(config.emailPort),
secure: parseInt(config.emailPort) === 465,
auth: {
user: config.emailUser,
pass: config.emailPassword,
},
})
const mailOptions = {
from: config.emailFrom,
to: email,
subject: `Sermon Notes: ${sermonTitle}`,
text: `
Sermon Notes for ${firstName}
Title: ${sermonTitle}
Date: ${sermonDate}
Bible References:
${bibleReferences}
Personal Appliance:
${personalAppliance}
Pastor's Challenge:
${pastorsChallenge}
My Notes:
${userNotes || 'No notes taken'}
`,
html: `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px;">
<h1 style="color: #333; border-bottom: 3px solid #4CAF50; padding-bottom: 10px;">Sermon Notes</h1>
<div style="margin: 20px 0;">
<h2 style="color: #4CAF50; margin-bottom: 5px;">${sermonTitle}</h2>
<p style="color: #666; margin-top: 0;">${sermonDate}</p>
</div>
<div style="background-color: #E3F2FD; padding: 15px; border-radius: 5px; margin: 20px 0;">
<h3 style="color: #1976D2; margin-top: 0;">Bible References</h3>
<div style="color: #333; white-space: pre-wrap;">${bibleReferences}</div>
</div>
<div style="background-color: #E8F5E9; padding: 15px; border-radius: 5px; margin: 20px 0;">
<h3 style="color: #388E3C; margin-top: 0;">Personal Appliance</h3>
<div style="color: #333; white-space: pre-wrap;">${personalAppliance}</div>
</div>
<div style="background-color: #F3E5F5; padding: 15px; border-radius: 5px; margin: 20px 0;">
<h3 style="color: #7B1FA2; margin-top: 0;">Pastor's Challenge</h3>
<div style="color: #333; white-space: pre-wrap;">${pastorsChallenge}</div>
</div>
<div style="background-color: #FFF9C4; padding: 15px; border-radius: 5px; margin: 20px 0;">
<h3 style="color: #F57F17; margin-top: 0;">My Notes</h3>
<div style="color: #333; white-space: pre-wrap;">${userNotes || '<em>No notes taken</em>'}</div>
</div>
<div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd; color: #666; font-size: 12px;">
<p>This email was sent from New Life Christian Church Sermon Notes</p>
</div>
</div>
`,
}
await transporter.sendMail(mailOptions)
}