Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/oversize-route-builder / server/utils/email.js |
| Date | Not specified in source |
| Repository | Janady13/oversize-route-builder |
| Revision | 8630196cd162b68cf069cdabcc5487b49dcc625d |
| Branch | main |
| Path or archive member | server/utils/email.js |
| Original SHA-256 | 4ae624a5e0431b98c5998c1d02e14792104216753f387221e0f42929c2366348 |
| Git blob SHA | 3a3e5c6db072e243b5c2ff387b59ede346b05193 |
| Reading-copy SHA-256 | 4ae624a5e0431b98c5998c1d02e14792104216753f387221e0f42929c2366348 |
Recovered source transcript
Download complete source text ↓181 lines · 6.5 KB
const nodemailer = require('nodemailer');
// Create transporter
const transporter = nodemailer.createTransport({
host: process.env.EMAIL_HOST,
port: process.env.EMAIL_PORT,
secure: false,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASSWORD
}
});
const sendVerificationEmail = async (email, token) => {
const verificationUrl = `${process.env.FRONTEND_URL}/verify-email/${token}`;
const mailOptions = {
from: process.env.EMAIL_FROM,
to: email,
subject: 'Verify Your Email - Oversize Route Builder',
html: `
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #2563eb; color: white; padding: 20px; text-align: center; }
.content { padding: 30px; background: #f9fafb; }
.button { display: inline-block; padding: 12px 30px; background: #2563eb; color: white;
text-decoration: none; border-radius: 5px; margin: 20px 0; }
.footer { padding: 20px; text-align: center; font-size: 12px; color: #666; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Welcome to Oversize Route Builder</h1>
</div>
<div class="content">
<h2>Verify Your Email Address</h2>
<p>Thank you for registering! Please verify your email address to activate your account and start building compliant routes for your oversized loads.</p>
<p style="text-align: center;">
<a href="${verificationUrl}" class="button">Verify Email Address</a>
</p>
<p>Or copy and paste this link into your browser:</p>
<p style="word-break: break-all; color: #666;">${verificationUrl}</p>
<p>This link will expire in 24 hours.</p>
</div>
<div class="footer">
<p>If you didn't create an account, please ignore this email.</p>
<p>© ${new Date().getFullYear()} Oversize Route Builder. All rights reserved.</p>
</div>
</div>
</body>
</html>
`
};
try {
await transporter.sendMail(mailOptions);
console.log('Verification email sent to:', email);
} catch (error) {
console.error('Error sending verification email:', error);
throw error;
}
};
const sendPasswordResetEmail = async (email, token) => {
const resetUrl = `${process.env.FRONTEND_URL}/reset-password/${token}`;
const mailOptions = {
from: process.env.EMAIL_FROM,
to: email,
subject: 'Reset Your Password - Oversize Route Builder',
html: `
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #2563eb; color: white; padding: 20px; text-align: center; }
.content { padding: 30px; background: #f9fafb; }
.button { display: inline-block; padding: 12px 30px; background: #2563eb; color: white;
text-decoration: none; border-radius: 5px; margin: 20px 0; }
.footer { padding: 20px; text-align: center; font-size: 12px; color: #666; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Password Reset Request</h1>
</div>
<div class="content">
<h2>Reset Your Password</h2>
<p>We received a request to reset your password. Click the button below to create a new password:</p>
<p style="text-align: center;">
<a href="${resetUrl}" class="button">Reset Password</a>
</p>
<p>Or copy and paste this link into your browser:</p>
<p style="word-break: break-all; color: #666;">${resetUrl}</p>
<p>This link will expire in 1 hour.</p>
<p><strong>If you didn't request a password reset, please ignore this email.</strong></p>
</div>
<div class="footer">
<p>© ${new Date().getFullYear()} Oversize Route Builder. All rights reserved.</p>
</div>
</div>
</body>
</html>
`
};
try {
await transporter.sendMail(mailOptions);
console.log('Password reset email sent to:', email);
} catch (error) {
console.error('Error sending password reset email:', error);
throw error;
}
};
const sendPermitProcessedEmail = async (email, permitNumber, state) => {
const dashboardUrl = `${process.env.FRONTEND_URL}/dashboard/permits`;
const mailOptions = {
from: process.env.EMAIL_FROM,
to: email,
subject: `Permit ${permitNumber} Processed Successfully`,
html: `
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #10b981; color: white; padding: 20px; text-align: center; }
.content { padding: 30px; background: #f9fafb; }
.button { display: inline-block; padding: 12px 30px; background: #2563eb; color: white;
text-decoration: none; border-radius: 5px; margin: 20px 0; }
.footer { padding: 20px; text-align: center; font-size: 12px; color: #666; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>✓ Permit Processed</h1>
</div>
<div class="content">
<h2>Your permit has been processed successfully!</h2>
<p><strong>Permit Number:</strong> ${permitNumber}</p>
<p><strong>State:</strong> ${state}</p>
<p>Your route information has been extracted and is ready for viewing.</p>
<p style="text-align: center;">
<a href="${dashboardUrl}" class="button">View in Dashboard</a>
</p>
</div>
<div class="footer">
<p>© ${new Date().getFullYear()} Oversize Route Builder. All rights reserved.</p>
</div>
</div>
</body>
</html>
`
};
try {
await transporter.sendMail(mailOptions);
console.log('Permit processed email sent to:', email);
} catch (error) {
console.error('Error sending permit processed email:', error);
}
};
module.exports = {
sendVerificationEmail,
sendPasswordResetEmail,
sendPermitProcessedEmail
};