send mail

This commit is contained in:
Thomas Ruoff
2020-08-18 00:22:03 +02:00
parent 70d78427b1
commit d86f438f80
3 changed files with 50 additions and 5 deletions

33
helpers/mail.js Normal file
View File

@@ -0,0 +1,33 @@
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY
const SENDGRID_URL = 'https://api.sendgrid.com/v3/mail/send'
const BOOKING_ADMIN_EMAIL = 'tomru@mail.id0.link'
const FROM_EMAIL = 'thomasruoff@gmail.com'
async function sendMail(data) {
const response = await fetch(SENDGRID_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${SENDGRID_API_KEY}`,
},
body: JSON.stringify(data),
})
return response.json()
}
export async function sendReceivedBookingMail(booking) {
const data = {
personalizations: [
{
to: [{ email: BOOKING_ADMIN_EMAIL }],
},
],
from: { email: FROM_EMAIL },
subject: 'Pfadi Bussle - Buchung eingegangen!',
content: [
{ type: 'text/plain', value: `${JSON.stringify(booking, null, 4)}` },
],
}
await sendMail(data)
}