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:
@@ -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 {
|
||||||
|
|||||||
@@ -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.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user