export function buildSampleEmail(params: { title?: string; message?: string; appUrl?: string }) {
const title = params.title || 'Welcome to Your App';
const message =
params.message ||
'This is a sample transactional email sent via Nodemailer. You can customize this template as needed.';
const appUrl = safeHttpUrl(params.appUrl || process.env.NEXT_PUBLIC_APP_URL);
const escapedAppUrl = escapeHtml(appUrl);
// Basic responsive email with inline styles for broad client support
return `
${escapeHtml(title)}
|
${escapeHtml(
title
)}
Notification from Your App
|
${escapeHtml(message)}
You can safely edit this template at src/emails/sample.ts.
|
|
|
|
`;
}
function escapeHtml(str: string) {
return str
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
function safeHttpUrl(value?: string) {
if (!value) return 'http://localhost:3000';
try {
const url = new URL(value);
return url.protocol === 'http:' || url.protocol === 'https:' ? url.toString() : 'http://localhost:3000';
} catch {
return 'http://localhost:3000';
}
}