Skip to content

Commit 04460d9

Browse files
committed
stop if things are missing
1 parent f955bdb commit 04460d9

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

utilities/mailer/index.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ export const sendMail = async (email, subject, message) => {
3636
htmlTemplate = htmlTemplate.replace("{{subject}}", subject)
3737
htmlTemplate = htmlTemplate.replace("{{messageBody}}", message)
3838

39+
// Stop execution if any of the required environment variables are not set
40+
const requiredEnvVars = [
41+
"SMTP_HOST",
42+
"SMTP_PORT",
43+
"TPEN_SUPPORT_EMAIL",
44+
"TPEN_EMAIL_CC"
45+
]
46+
47+
requiredEnvVars.forEach(varName => {
48+
if (!process.env[varName]) {
49+
return {
50+
status: 500,
51+
message: `${varName} environment variable is not set.`
52+
}
53+
}
54+
})
55+
3956
try {
4057
const transporter = nodemailer.createTransport({
4158
host: process.env.SMTP_HOST,

0 commit comments

Comments
 (0)