2023-02-16 22:39:57 +00:00
|
|
|
import type SendmailTransport from "nodemailer/lib/sendmail-transport";
|
|
|
|
import type SMTPConnection from "nodemailer/lib/smtp-connection";
|
2022-02-10 10:44:46 +00:00
|
|
|
|
2022-04-21 20:32:25 +00:00
|
|
|
import { isENVDev } from "@calcom/lib/env";
|
|
|
|
|
2022-02-10 10:44:46 +00:00
|
|
|
function detectTransport(): SendmailTransport.Options | SMTPConnection.Options | string {
|
2021-08-19 12:27:01 +00:00
|
|
|
if (process.env.EMAIL_SERVER) {
|
|
|
|
return process.env.EMAIL_SERVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.EMAIL_SERVER_HOST) {
|
2023-06-06 11:59:57 +00:00
|
|
|
const port = parseInt(process.env.EMAIL_SERVER_PORT || "");
|
2021-08-19 12:27:01 +00:00
|
|
|
const transport = {
|
|
|
|
host: process.env.EMAIL_SERVER_HOST,
|
|
|
|
port,
|
|
|
|
auth: {
|
|
|
|
user: process.env.EMAIL_SERVER_USER,
|
|
|
|
pass: process.env.EMAIL_SERVER_PASSWORD,
|
|
|
|
},
|
|
|
|
secure: port === 465,
|
2022-04-21 20:32:25 +00:00
|
|
|
tls: {
|
|
|
|
rejectUnauthorized: isENVDev ? false : true,
|
|
|
|
},
|
2021-08-19 12:27:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return transport;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
sendmail: true,
|
|
|
|
newline: "unix",
|
|
|
|
path: "/usr/sbin/sendmail",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const serverConfig = {
|
|
|
|
transport: detectTransport(),
|
|
|
|
from: process.env.EMAIL_FROM,
|
|
|
|
};
|