From 7973663b2a195ceb0b5abe0933712c7068b40fe1 Mon Sep 17 00:00:00 2001 From: Ahmed Al-Taiar Date: Wed, 16 Oct 2024 21:45:55 -0400 Subject: [PATCH] Allow separate from and to emails --- .env.defaults | 2 ++ .env.example | 2 ++ Dockerfile | 2 ++ README.md | 2 ++ api/src/lib/email.ts | 2 +- docker-compose.yml | 2 ++ scripts/seed.ts | 12 ++++++++++-- 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.env.defaults b/.env.defaults index bd822e6..551cbef 100644 --- a/.env.defaults +++ b/.env.defaults @@ -22,6 +22,8 @@ SMTP_HOST=smtp.example.com SMTP_PORT=465 SMTP_SECURE=true SMTP_USER=noreply@example.com +EMAIL_FROM=noreply@example.com +EMAIL_TO=email@example.com SMTP_PASSWORD=password DOMAIN=example.com diff --git a/.env.example b/.env.example index d28f7b0..d722b95 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,8 @@ SMTP_HOST=smtp.example.com SMTP_PORT=465 SMTP_SECURE=true SMTP_USER=noreply@example.com +EMAIL_FROM=noreply@example.com +EMAIL_TO=email@example.com SMTP_PASSWORD=password DOMAIN=example.com diff --git a/Dockerfile b/Dockerfile index fb76e4f..08ae7b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,6 +48,8 @@ ARG SMTP_PORT ARG SMTP_SECURE ARG SMTP_USER ARG SMTP_PASSWORD +ARG EMAIL_FROM +ARG EMAIL_TO ARG FIRST_NAME ARG LAST_NAME diff --git a/README.md b/README.md index ea56671..91cf1ef 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ services: - SMTP_PORT=465 - SMTP_SECURE=true - SMTP_USER=noreply@example.com + - EMAIL_FROM=noreply@example.com + - EMAIL_TO=email@example.com - SMTP_PASSWORD=password - DOMAIN=portfolio.example.com - API_DOMAIN=api.portfolio.example.com diff --git a/api/src/lib/email.ts b/api/src/lib/email.ts index a8dc355..33328b6 100644 --- a/api/src/lib/email.ts +++ b/api/src/lib/email.ts @@ -19,7 +19,7 @@ const transporter = nodemailer.createTransport({ export const sendEmail = async ({ to, subject, text, html }: Options) => await transporter.sendMail({ - from: `${process.env.FIRST_NAME} ${process.env.LAST_NAME} <${process.env.GMAIL}>`, + from: `${process.env.FIRST_NAME} ${process.env.LAST_NAME} <${process.env.EMAIL_FROM}>`, to: Array.isArray(to) ? to : [to], subject, text, diff --git a/docker-compose.yml b/docker-compose.yml index d41709a..e87f32e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,8 @@ services: - SMTP_PORT=465 - SMTP_SECURE=true - SMTP_USER=noreply@example.com + - EMAIL_FROM=noreply@example.com + - EMAIL_TO=email@example.com - SMTP_PASSWORD=password - DOMAIN=portfolio.example.com - API_DOMAIN=api.portfolio.example.com diff --git a/scripts/seed.ts b/scripts/seed.ts index 072e64e..0994d75 100644 --- a/scripts/seed.ts +++ b/scripts/seed.ts @@ -9,7 +9,7 @@ export default async () => { try { const admin = { username: 'admin', - email: process.env.GMAIL, + email: process.env.EMAIL_TO, password: process.env.SMTP_PASSWORD, } @@ -17,7 +17,7 @@ export default async () => { const existingAdmin = await db.user.findFirst({ where: { - email: admin.email, + username: admin.username, }, }) @@ -30,6 +30,14 @@ export default async () => { salt, }, }) + else + await db.user.update({ + where: { id: existingAdmin.id }, + data: { + username: admin.username, + email: admin.email, + }, + }) const titles = await db.titles.findFirst()