-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: sending email when free account creation code is created
- Loading branch information
Showing
4 changed files
with
52 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,41 @@ | ||
// /** Sendgrid email helpers, backend only. */ | ||
// This is currently being handled by the Whalesplainer hosted at https://create-api.anchor.link | ||
// If this service ends up replacing Whalesplainer then, this will need to be uncommented. | ||
import { SENDGRID_KEY, SENDGRID_TEMPLATE, SENDGRID_FROM } from '$env/static/private' | ||
|
||
// import { SENDGRID_KEY, SENDGRID_TEMPLATE, SENDGRID_FROM} from '$env/static/private' | ||
const key = SENDGRID_KEY | ||
const templateId = SENDGRID_TEMPLATE || 'd-1106a932fc984f14be0230c670820b38' | ||
const from = SENDGRID_FROM || '[email protected]' | ||
|
||
// const key = SENDGRID_KEY | ||
// const templateId = SENDGRID_TEMPLATE || 'd-1106a932fc984f14be0230c670820b38' | ||
// const from = SENDGRID_FROM || '[email protected]' | ||
|
||
if (!key) { | ||
console.log('Missing SENDGRID_KEY, will not send emails') | ||
} | ||
|
||
// if (!key) { | ||
// console.log('Missing SENDGRID_KEY, will not send emails') | ||
// } | ||
export async function sendEmail(to: string, data: Record<string, string>) { | ||
if (!key) return | ||
|
||
// export async function sendEmail(to: string, data: Record<string, string>) { | ||
// if (!key) return | ||
|
||
// const res = await fetch('https://api.sendgrid.com/v3/mail/send', { | ||
// body: JSON.stringify({ | ||
// from: { | ||
// email: from | ||
// }, | ||
// personalizations: [ | ||
// { | ||
// to: [{ email: to }], | ||
// dynamic_template_data: data | ||
// } | ||
// ], | ||
// template_id: templateId | ||
// }), | ||
// headers: { | ||
// Authorization: `Bearer ${key}`, | ||
// 'Content-Type': 'application/json' | ||
// }, | ||
// method: 'POST' | ||
// }) | ||
// if (res.status >= 400) { | ||
// const body = | ||
// parseInt(res.headers.get('content-length') || '0') > 0 | ||
// ? await res.text() | ||
// : `${res.status} ${res.statusText}` | ||
// throw new Error(`Sendgrid error: ${body}`) | ||
// } | ||
// } | ||
const res = await fetch('https://api.sendgrid.com/v3/mail/send', { | ||
body: JSON.stringify({ | ||
from: { | ||
email: from | ||
}, | ||
personalizations: [ | ||
{ | ||
to: [{ email: to }], | ||
dynamic_template_data: data | ||
} | ||
], | ||
template_id: templateId | ||
}), | ||
headers: { | ||
Authorization: `Bearer ${key}`, | ||
'Content-Type': 'application/json' | ||
}, | ||
method: 'POST' | ||
}) | ||
if (res.status >= 400) { | ||
const body = | ||
parseInt(res.headers.get('content-length') || '0') > 0 | ||
? await res.text() | ||
: `${res.status} ${res.statusText}` | ||
throw new Error(`Sendgrid error: ${body}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters