Send in Blue Wrapper Example
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
{ | |
"name": "send-in-blue-wrapper", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"@sendinblue/client": "^3.2.1", | |
"express": "^4.18.1" | |
}, | |
"devDependencies": { | |
"@types/express": "^4.17.13", | |
"@types/node": "^18.6.2" | |
} | |
} |
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
import SibSdk from "@sendinblue/client"; | |
import express from "express"; | |
const api = express(); | |
const apiInstance = new SibSdk.TransactionalEmailsApi(); | |
// TODO: obviously the mailbox should exist :) | |
const recipientEmail = process.env.GROUP_ACCOUNT_EMAIL as string; | |
apiInstance.setApiKey( | |
SibSdk.TransactionalEmailsApiApiKeys.apiKey, | |
process.env.SEND_IN_BLUE_API_KEY as string | |
); | |
api.post("/send_mail", async (req, res) => { | |
const { templateId, ...params } = req.body; | |
try { | |
if (!templateId) { | |
throw new Error("Template must be set."); | |
} | |
const email: SibSdk.SendSmtpEmail = { | |
to: [ | |
{ | |
email: recipientEmail, | |
name: "From Name", | |
}, | |
], | |
templateId: parseInt(templateId), | |
params, | |
}; | |
await apiInstance.sendTransacEmail(email); | |
res.send({ success: true }); | |
} catch (err) { | |
res.status(500).send(err.toString()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment