Skip to content

Commit

Permalink
chore: Update SMTP configuration for Charter Africa CMS
Browse files Browse the repository at this point in the history
Update the SMTP configuration in the Charter Africa CMS server file to use the environment variables `SMTP_PASS`, `SMTP_FROM_NAME`, `SMTP_FROM_ADDRESS`, and `SMTP_PORT` for the SMTP authentication password, from name, from address, and port respectively. This ensures that the SMTP settings can be easily customized and managed.
  • Loading branch information
koechkevin committed Nov 14, 2024
1 parent 8d5860e commit 1eeadee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion apps/charterafrica/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"monaco-editor": "catalog:",
"next": "catalog:",
"next-seo": "catalog:",
"nodemailer-sendgrid": "catalog:",
"payload": "catalog:",
"prop-types": "catalog:",
"qs": "catalog:",
Expand Down
31 changes: 22 additions & 9 deletions apps/charterafrica/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { spawn } from "child_process";
import { loadEnvConfig } from "@next/env";
import express from "express";
import next from "next";
import nodemailerSendgrid from "nodemailer-sendgrid";
import payload from "payload";
import { Payload } from "payload/dist/payload";

Expand All @@ -20,8 +19,17 @@ const dev = process.env.NODE_ENV !== "production";
// https://github.com/vercel/next.js/discussions/33835#discussioncomment-2559392
const hostname = process.env.NEXT_HOSTNAME || "localhost";
const port = Number.parseInt(process.env.PORT || "3000", 10);
const sendGridAPIKey = process.env.SENDGRID_API_KEY;

const smtpAuthPass = process.env.SMTP_PASS || process.env.SENDGRID_API_KEY;
const smtpFromName =
process.env.SMTP_FROM_NAME ||
process.env.SENDGRID_FROM_NAME ||
"Charter Africa CMS";
const smtpFromAddress =
process.env.SMTP_FROM_ADDRESS ||
process.env.SENDGRID_FROM_EMAIL ||
"noreply@codeforafrica.org";
const smtpPort = Number(process.env.SMTP_PORT || 587);
// Make sure commands gracefully respect termination signals (e.g. from Docker)
// Allow the graceful termination to be manually configurable
if (!process.env.NEXT_MANUAL_SIG_HANDLE) {
Expand All @@ -35,15 +43,20 @@ const start = async (): Promise<void> => {
let localPayload: Payload;
try {
localPayload = await payload.init({
...(sendGridAPIKey
...(smtpAuthPass
? {
email: {
transportOptions: nodemailerSendgrid({
apiKey: sendGridAPIKey,
}),
fromName: process.env.SENDGRID_FROM_NAME || "Admin",
fromAddress:
process.env.SENDGRID_FROM_EMAIL || "admin@example.com",
transportOptions: {
auth: {
user: process.env.SMTP_USER || "apikey",
pass: smtpAuthPass,
},
host: process.env.SMTP_HOST || "smtp.sendgrid.net",
port: smtpPort,
secure: smtpPort === 465, // true for port 465, false (the default) for 587 and others
},
fromName: smtpFromName,
fromAddress: smtpFromAddress,
},
}
: undefined),
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1eeadee

Please sign in to comment.