Update TypeScript version and enhance ContactForm and email handling

- Upgraded TypeScript dependency from 5.7.3 to 5.8.3 for improved type checking and features.
- Modified ContactForm component to include a hidden input for the domain, capturing the current hostname.
- Updated API contact handling to log and utilize the domain information in email notifications.
- Refactored email sending functions to conditionally include the domain in the sender's address for better context.
This commit is contained in:
2025-06-26 23:40:44 +02:00
parent 559bd3e983
commit 246edb3952
5 changed files with 31 additions and 13 deletions

View File

@@ -140,14 +140,18 @@ export function logEmailAttempt(success: boolean, recipient: string, subject: st
}
// Send an email
export async function sendEmail(to: string, subject: string, html: string, text: string): Promise<boolean> {
export async function sendEmail(to: string, subject: string, html: string, text: string, domain?: string): Promise<boolean> {
// Initialize transporter if not already done
if (!transporter) {
initializeTransporter();
}
try {
const fromAddress = isProduction ? `"${WEBSITE_NAME}" <${SMTP_USER || 'noreply@' + WEBSITE_NAME}>` : `"${WEBSITE_NAME}" <${ADMIN_EMAIL}>`;
const fromAddress = isProduction
? domain
? `"${WEBSITE_NAME}" <${SMTP_USER || 'info'}@${domain}>`
: `"${WEBSITE_NAME}" <${SMTP_USER || 'noreply@' + WEBSITE_NAME}>`
: `"${WEBSITE_NAME}" <${ADMIN_EMAIL}>`;
const mailOptions = {
from: fromAddress,
@@ -197,7 +201,8 @@ export async function sendAdminNotification(
email: string,
message: string,
ipAddress?: string,
userAgent?: string
userAgent?: string,
domain?: string
): Promise<boolean> {
// Validate inputs
if (!name || name.trim() === '') {
@@ -239,11 +244,11 @@ Time: ${new Date().toLocaleString()}
This message was sent from the contact form on ${WEBSITE_NAME}
`;
return sendEmail(ADMIN_EMAIL, subject, html, text);
return sendEmail(ADMIN_EMAIL, subject, html, text, domain);
}
// Send user confirmation email
export async function sendUserConfirmation(name: string, email: string, message: string): Promise<boolean> {
export async function sendUserConfirmation(name: string, email: string, message: string, domain?: string): Promise<boolean> {
// Validate inputs
if (!name || name.trim() === '') {
console.error('Cannot send user confirmation: name is empty');
@@ -280,7 +285,7 @@ ${WEBSITE_NAME} Team
This is an automated message, please do not reply directly to this email.
`;
return sendEmail(email, subject, html, text);
return sendEmail(email, subject, html, text, domain);
}
// Initialize the email system