Created the mail util

This commit is contained in:
Mathias Wagner 2023-01-15 15:55:50 +01:00
parent 4afaa8ae32
commit 34530e1682
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

19
src/utils/email.ts Normal file
View File

@ -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);
});