mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-06-01 01:54:00 +00:00
Move next js project to archive (#207)
This commit is contained in:
35
archive/next-js-web-app/src/config/sparkpost/sendEmail.ts
Normal file
35
archive/next-js-web-app/src/config/sparkpost/sendEmail.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { SPARKPOST_API_KEY, SPARKPOST_SENDER_ADDRESS } from '../env';
|
||||
|
||||
interface EmailParams {
|
||||
address: string;
|
||||
text: string;
|
||||
html: string;
|
||||
subject: string;
|
||||
}
|
||||
|
||||
const sendEmail = async ({ address, text, html, subject }: EmailParams) => {
|
||||
const from = SPARKPOST_SENDER_ADDRESS;
|
||||
|
||||
const data = {
|
||||
recipients: [{ address }],
|
||||
content: { from, subject, text, html },
|
||||
};
|
||||
|
||||
const transmissionsEndpoint = 'https://api.sparkpost.com/api/v1/transmissions';
|
||||
|
||||
const response = await fetch(transmissionsEndpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
Authorization: SPARKPOST_API_KEY,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Sparkpost API returned status code ${response.status}`);
|
||||
}
|
||||
};
|
||||
|
||||
export default sendEmail;
|
||||
Reference in New Issue
Block a user