From 34530e1682b853b1a060431836e488f6abcd1e13 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 15 Jan 2023 15:55:50 +0100 Subject: [PATCH] Created the mail util --- src/utils/email.ts | 19 +++++++++++++++++++ 1 file changed, 19 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..16c8e76 --- /dev/null +++ b/src/utils/email.ts @@ -0,0 +1,19 @@ +import { createTransport, SentMessageInfo } from "nodemailer"; +import { Options } from "nodemailer/lib/mailer"; +import * as process from "process"; + +const transport = createTransport({ + service: process.env.MAIL_SERVICE || "gmail", + 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.USER || "noreply@licenseapi.de", +}, (err, info) => { + if (err !== null && error) return error(err); + + if (success) success(info); +}); \ No newline at end of file