From 0db8839915798a3a76ca285b93b67368866db061 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 20 Jul 2024 12:30:21 +0200 Subject: [PATCH] Create email.ts util --- src/utils/email.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/utils/email.ts diff --git a/src/utils/email.ts b/src/utils/email.ts new file mode 100644 index 0000000..130d6f0 --- /dev/null +++ b/src/utils/email.ts @@ -0,0 +1,20 @@ +import { createTransport, SentMessageInfo } from "nodemailer"; +import { Options } from "nodemailer/lib/mailer"; +import * as process from "process"; + +const transport = createTransport({ + host: process.env.MAIL_SERVER || "smtp.gmail.com", + port: parseInt(process.env.MAIL_PORT || "587"), + auth: { + user: process.env.MAIL_USER || "noreply@licenseapi.de", + pass: process.env.MAIL_PASS, + }, +}); + +export const sendMail = (options: Options, success?: (info: SentMessageInfo) => void, error?: (msg: Error) => void) => transport.sendMail({ + ...options, from: process.env.MAIL_USER || "noreply@licenseapi.de", +}, (err, info) => { + if (err !== null && error) return error(err); + + if (success) success(info); +}); \ No newline at end of file