From 4e86a82aa30a85c7f00ab043c461e1765d06a3ec Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Sat, 13 Apr 2024 20:45:15 +0300 Subject: [PATCH] email test mode implemented - bypass all targers unless production --- .env | 2 +- .env.production | 1 + src/helpers/email.js | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.env b/.env index eddde85..57f1728 100644 --- a/.env +++ b/.env @@ -46,7 +46,7 @@ GITHUB_SECRET= TWITTER_ID= TWITTER_SECRET= - +EMAIL_BYPASS_TO=mwitnessing@gmail.com # EMAIL_SERVER=smtp://8ec69527ff2104:c7bc05f171c96c@smtp.mailtrap.io:2525 EMAIL_FROM=noreply@mwitnessing.com diff --git a/.env.production b/.env.production index 82f44eb..112901f 100644 --- a/.env.production +++ b/.env.production @@ -9,6 +9,7 @@ NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638 DATABASE=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia +EMAIL_BYPASS_TO= MAILTRAP_HOST_BULK=bulk.smtp.mailtrap.io MAILTRAP_HOST=live.smtp.mailtrap.io MAILTRAP_USER=api diff --git a/src/helpers/email.js b/src/helpers/email.js index e543244..4288e5b 100644 --- a/src/helpers/email.js +++ b/src/helpers/email.js @@ -122,6 +122,12 @@ exports.SendEmail = async function (to, subject, text, html, attachments = []) { let sender = '"Специално Свидетелстване София - тест" '; const emailAddresses = normalizeEmailAddresses(to) + const bypassEmailReccipients = process.env.EMAIL_BYPASS_TO || null; + if (bypassEmailReccipients !== null && bypassEmailReccipients.length > 0) { + emailAddresses = "[" + bypassEmailReccipients + "]"; + console.log("Emails bypassed. All mails sent to: " + emailAddresses); + } + const message = { from: sender, to: emailAddresses,