Skip to content

Instantly share code, notes, and snippets.

@leomelzer
Created August 2, 2022 13:05
Show Gist options
  • Save leomelzer/f8050b25f5a3ad22a7a8fdf80b570768 to your computer and use it in GitHub Desktop.
Save leomelzer/f8050b25f5a3ad22a7a8fdf80b570768 to your computer and use it in GitHub Desktop.
Send in Blue Wrapper Example
{
"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"
}
}
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