Create common email send function

This commit is contained in:
regalijan 2023-10-19 16:51:00 -04:00
parent 8786363601
commit 86109eb770
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

29
functions/email.ts Normal file
View File

@ -0,0 +1,29 @@
export default async function (
email: string,
sendingKey: string,
subject: string,
template: string,
variables: {
[k: string]: string;
},
) {
const body = new FormData();
body.append("from", "noreply@mail.carcrushers.cc");
body.append("subject", subject);
body.append("template", template);
body.append("to", email);
for (const [name, value] of Object.entries(variables))
body.append(`v:${name}`, value);
return await fetch(
"https://api.mailgun.net/v3/mail.carcrushers.cc/messages",
{
body,
headers: {
authorization: `Basic ${btoa("api" + ":" + sendingKey)}`,
},
method: "POST",
},
);
}