Skip to content

Commit

Permalink
Merge pull request #1002 from CodeForAfrica/ft/charter_africa_smtp_su…
Browse files Browse the repository at this point in the history
…pport

Charter Africa: Update SMTP configuration
  • Loading branch information
koechkevin authored Nov 15, 2024
2 parents f4e0b0c + 1eeadee commit 22519b6
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 ||
"[email protected]";
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 || "[email protected]",
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 22519b6

Please sign in to comment.