Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create common email send function
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 8786363 commit 86109eb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions functions/email.ts
@@ -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",
},
);
}

0 comments on commit 86109eb

Please sign in to comment.