2021-06-24 15:59:11 +00:00
|
|
|
import nodemailer, { SentMessageInfo } from "nodemailer";
|
2021-10-28 22:58:26 +00:00
|
|
|
import { SendMailOptions } from "nodemailer";
|
2021-06-24 15:59:11 +00:00
|
|
|
|
2021-09-22 19:52:38 +00:00
|
|
|
import { serverConfig } from "../serverConfig";
|
|
|
|
|
2021-10-28 22:58:26 +00:00
|
|
|
const sendEmail = ({ to, subject, text, html }: SendMailOptions): Promise<string | SentMessageInfo> =>
|
2021-06-24 15:59:11 +00:00
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
const { transport, from } = serverConfig;
|
|
|
|
|
|
|
|
if (!to || !subject || (!text && !html)) {
|
|
|
|
return reject("Missing required elements to send email.");
|
|
|
|
}
|
|
|
|
|
|
|
|
nodemailer.createTransport(transport).sendMail(
|
|
|
|
{
|
2021-09-21 09:59:34 +00:00
|
|
|
from: `Cal.com ${from}`,
|
2021-06-24 15:59:11 +00:00
|
|
|
to,
|
|
|
|
subject,
|
|
|
|
text,
|
|
|
|
html,
|
|
|
|
},
|
|
|
|
(error, info) => {
|
|
|
|
if (error) {
|
|
|
|
console.error("SEND_INVITATION_NOTIFICATION_ERROR", to, error);
|
|
|
|
return reject(error.message);
|
|
|
|
}
|
|
|
|
return resolve(info);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default sendEmail;
|