feat: Add optional SMTP_NAME configuration for connecting to SMTP servers that require the client to have a specific hostname

This commit is contained in:
Tom Moor
2023-01-13 21:49:57 -05:00
parent d20f379943
commit e3db7455b3
2 changed files with 12 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import nodemailer, { Transporter } from "nodemailer"; import nodemailer, { Transporter } from "nodemailer";
import SMTPTransport from "nodemailer/lib/smtp-transport";
import Oy from "oy-vey"; import Oy from "oy-vey";
import env from "@server/env"; import env from "@server/env";
import Logger from "@server/logging/Logger"; import Logger from "@server/logging/Logger";
@@ -101,8 +102,9 @@ export class Mailer {
} }
}; };
private getOptions() { private getOptions(): SMTPTransport.Options {
return { return {
name: env.SMTP_NAME,
host: env.SMTP_HOST, host: env.SMTP_HOST,
port: env.SMTP_PORT, port: env.SMTP_PORT,
secure: env.SMTP_SECURE ?? env.ENVIRONMENT === "production", 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 { try {
const testAccount = await nodemailer.createTestAccount(); const testAccount = await nodemailer.createTestAccount();
return { return {

View File

@@ -264,6 +264,12 @@ export class Environment {
*/ */
public SMTP_HOST = process.env.SMTP_HOST; 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. * The port of your SMTP server.
*/ */