improve booking received mail

This commit is contained in:
Thomas Ruoff
2020-08-18 23:45:28 +02:00
parent b9ebfafc63
commit 194ac0aca1

View File

@@ -1,18 +1,33 @@
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY
const SENDGRID_URL = 'https://api.sendgrid.com/v3/mail/send'
// TODO: move to env
const BOOKING_ADMIN_EMAIL = 'tomru@mail.id0.link'
const FROM_EMAIL = 'thomasruoff@gmail.com'
const FROM_EMAIL = 'pfadibussle@mail.id0.link'
if (!SENDGRID_API_KEY) {
throw new Error('NO SENDGRID_API_KEY set!')
}
if (!SENDGRID_API_KEY) {
throw new Error('NO SENDGRID_API_KEY set!')
}
async function sendMail(data) {
const response = await fetch(SENDGRID_URL, {
const fetchOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${SENDGRID_API_KEY}`,
},
body: JSON.stringify(data),
})
return response.json()
}
const response = await fetch(SENDGRID_URL, fetchOptions)
if (!repsonse.ok) {
throw new Error(
`Failed to send booking ${data._id} to booking admin with status ${response.status}: ${response.statusText}`
)
}
}
export async function sendReceivedBookingMail(booking) {