fix email notifications

This commit is contained in:
ismail 2026-02-02 19:44:02 +01:00
parent b270cbaba4
commit 36b95da09d
3 changed files with 22 additions and 8 deletions

View File

@ -37,7 +37,7 @@ CREATE TABLE IF NOT EXISTS users (
-- 4. Insert root admin user (password: 3DBFC7FEF43B45E887C8E54205C8EC8F) -- 4. Insert root admin user (password: 3DBFC7FEF43B45E887C8E54205C8EC8F)
INSERT IGNORE INTO users (email, username, password_hash, full_name, role, email_verified) VALUES INSERT IGNORE INTO users (email, username, password_hash, full_name, role, email_verified) VALUES
('root@nordicstorium.com', 'root', '$2b$10$MDURVVPDTo60o.W5rHJOPex3jwR8.s.xc5e1dpYF8DG7bu5SXXwLq', 'Root Administrator', 'admin', TRUE); ('root@nordicstorium.se', 'root', '$2b$10$MDURVVPDTo60o.W5rHJOPex3jwR8.s.xc5e1dpYF8DG7bu5SXXwLq', 'Root Administrator', 'admin', TRUE);
-- 5. Create categories table (Required for webshop) -- 5. Create categories table (Required for webshop)
CREATE TABLE IF NOT EXISTS categories ( CREATE TABLE IF NOT EXISTS categories (

View File

@ -141,7 +141,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
conversation.user_email, conversation.user_email,
`Nytt svar: ${conversation.subject}`, `Nytt svar: ${conversation.subject}`,
'Nordic Storium Support', 'Nordic Storium Support',
process.env.SMTP_FROM || 'support@nordicstorium.com', process.env.SMTP_FROM || 'info@nordicstorium.se',
null, null,
null, null,
content, content,

View File

@ -13,7 +13,7 @@ const transporter = nodemailer.createTransport({
export const sendEmail = async (to: string, subject: string, html: string) => { export const sendEmail = async (to: string, subject: string, html: string) => {
try { try {
const info = await transporter.sendMail({ const info = await transporter.sendMail({
from: `"Nordic Storium" <${process.env.SMTP_FROM || 'noreply@nordicstorium.com'}>`, from: `"Nordic Storium" <${process.env.SMTP_FROM || 'info@nordicstorium.se'}>`,
to, to,
subject, subject,
html, html,
@ -27,6 +27,14 @@ export const sendEmail = async (to: string, subject: string, html: string) => {
}; };
const premiumTemplate = (content: string) => ` const premiumTemplate = (content: string) => `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nordic Storium</title>
</head>
<body style="margin: 0; padding: 0; background-color: #f4f4f4;">
<div style="font-family: 'Inter', -apple-system, sans-serif; max-width: 600px; margin: 40px auto; border: 1px solid #000000; color: #000000; background: #ffffff; overflow: hidden;"> <div style="font-family: 'Inter', -apple-system, sans-serif; max-width: 600px; margin: 40px auto; border: 1px solid #000000; color: #000000; background: #ffffff; overflow: hidden;">
<div style="background: linear-gradient(135deg, #0a192f 0%, #020c1b 100%); padding: 40px; text-align: center; border-bottom: 1px solid #000000;"> <div style="background: linear-gradient(135deg, #0a192f 0%, #020c1b 100%); padding: 40px; text-align: center; border-bottom: 1px solid #000000;">
<h1 style="font-size: 16px; font-weight: 900; text-transform: uppercase; letter-spacing: 4px; margin: 0; color: #ffffff;">Nordic Storium</h1> <h1 style="font-size: 16px; font-weight: 900; text-transform: uppercase; letter-spacing: 4px; margin: 0; color: #ffffff;">Nordic Storium</h1>
@ -45,6 +53,8 @@ const premiumTemplate = (content: string) => `
</div> </div>
</div> </div>
</div> </div>
</body>
</html>
`; `;
export const sendVerificationEmail = async (email: string, token: string) => { export const sendVerificationEmail = async (email: string, token: string) => {
@ -92,7 +102,7 @@ export const sendPasswordResetEmail = async (email: string, token: string) => {
}; };
export const sendContactEmail = async (name: string, email: string, subject: string, message: string) => { export const sendContactEmail = async (name: string, email: string, subject: string, message: string) => {
const adminEmail = process.env.CONTACT_EMAIL || 'admin@nordicstorium.com'; const adminEmail = process.env.CONTACT_EMAIL || 'info@nordicstorium.se';
const content = ` const content = `
<h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 20px; letter-spacing: 1px;">Nytt Kontaktmeddelande</h2> <h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 20px; letter-spacing: 1px;">Nytt Kontaktmeddelande</h2>
<div style="background: #f7fafc; padding: 20px; border-left: 4px solid #000000; margin-bottom: 30px;"> <div style="background: #f7fafc; padding: 20px; border-left: 4px solid #000000; margin-bottom: 30px;">
@ -119,7 +129,7 @@ export const sendSellFurnitureEmail = async (
message: string, message: string,
images: { filename: string; content: Buffer; contentType: string }[] images: { filename: string; content: Buffer; contentType: string }[]
) => { ) => {
const adminEmail = process.env.CONTACT_EMAIL || 'admin@nordicstorium.com'; const adminEmail = process.env.CONTACT_EMAIL || 'info@nordicstorium.se';
const content = ` const content = `
<h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 20px; letter-spacing: 1px;">Försäljning av Möbler</h2> <h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 20px; letter-spacing: 1px;">Försäljning av Möbler</h2>
<div style="background: #f7fafc; padding: 20px; border-left: 4px solid #000000; margin-bottom: 30px;"> <div style="background: #f7fafc; padding: 20px; border-left: 4px solid #000000; margin-bottom: 30px;">
@ -148,7 +158,7 @@ export const sendSellFurnitureEmail = async (
})); }));
const info = await transporter.sendMail({ const info = await transporter.sendMail({
from: `"Nordic Storium" <${process.env.SMTP_FROM || 'noreply@nordicstorium.com'}>`, from: `"Nordic Storium" <${process.env.SMTP_FROM || 'info@nordicstorium.se'}>`,
to: adminEmail, to: adminEmail,
subject: `Försäljning av Möbler: ${name}`, subject: `Försäljning av Möbler: ${name}`,
html: premiumTemplate(content), html: premiumTemplate(content),
@ -173,13 +183,17 @@ export const sendMessageNotification = async (
actionLink: string, actionLink: string,
actionText: string actionText: string
) => { ) => {
// Determine labels and values even if null to show clarity
const phoneDisplay = senderPhone || 'Ej angivet';
const personnummerDisplay = senderPersonnummer || 'Ej angivet';
const content = ` const content = `
<h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 20px; letter-spacing: 1px;">Nytt Meddelande</h2> <h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 20px; letter-spacing: 1px;">Nytt Meddelande</h2>
<div style="background: #f7fafc; padding: 20px; border-left: 4px solid #000000; margin-bottom: 30px;"> <div style="background: #f7fafc; padding: 20px; border-left: 4px solid #000000; margin-bottom: 30px;">
<p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Från:</strong> ${senderName}</p> <p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Från:</strong> ${senderName}</p>
<p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Email:</strong> <a href="mailto:${senderEmail}" style="color: #000000;">${senderEmail}</a></p> <p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Email:</strong> <a href="mailto:${senderEmail}" style="color: #000000;">${senderEmail}</a></p>
${senderPhone ? `<p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Telefon:</strong> ${senderPhone}</p>` : ''} <p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Telefon:</strong> ${phoneDisplay}</p>
${senderPersonnummer ? `<p style="font-size: 14px; margin: 0;"><strong>Personnummer:</strong> ${senderPersonnummer}</p>` : ''} <p style="font-size: 14px; margin: 0;"><strong>Personnummer:</strong> ${personnummerDisplay}</p>
</div> </div>
<div style="background: #ffffff; padding: 20px; border: 1px solid #e2e8f0; margin-bottom: 30px;"> <div style="background: #ffffff; padding: 20px; border: 1px solid #e2e8f0; margin-bottom: 30px;">