From e3db7455b33252e35b17a5c3520b21194b2b968f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 13 Jan 2023 21:49:57 -0500 Subject: [PATCH] feat: Add optional SMTP_NAME configuration for connecting to SMTP servers that require the client to have a specific hostname --- server/emails/mailer.tsx | 8 ++++++-- server/env.ts | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/emails/mailer.tsx b/server/emails/mailer.tsx index c6f584aa3..0d4dea367 100644 --- a/server/emails/mailer.tsx +++ b/server/emails/mailer.tsx @@ -1,4 +1,5 @@ import nodemailer, { Transporter } from "nodemailer"; +import SMTPTransport from "nodemailer/lib/smtp-transport"; import Oy from "oy-vey"; import env from "@server/env"; import Logger from "@server/logging/Logger"; @@ -101,8 +102,9 @@ export class Mailer { } }; - private getOptions() { + private getOptions(): SMTPTransport.Options { return { + name: env.SMTP_NAME, host: env.SMTP_HOST, port: env.SMTP_PORT, secure: env.SMTP_SECURE ?? env.ENVIRONMENT === "production", @@ -124,7 +126,9 @@ export class Mailer { }; } - private async getTestTransportOptions() { + private async getTestTransportOptions(): Promise< + SMTPTransport.Options | undefined + > { try { const testAccount = await nodemailer.createTestAccount(); return { diff --git a/server/env.ts b/server/env.ts index 5207687c3..1d7b72471 100644 --- a/server/env.ts +++ b/server/env.ts @@ -264,6 +264,12 @@ export class Environment { */ public SMTP_HOST = process.env.SMTP_HOST; + /** + * Optional hostname of the client, used for identifying to the server + * defaults to hostname of the machine. + */ + public SMTP_NAME = process.env.SMTP_NAME; + /** * The port of your SMTP server. */