This content originally appeared on Level Up Coding - Medium and was authored by Anjan Shomodder

In this article, we will learn how to send emails from Node.js with SendInBlue.
Video Tutorial
What is SendInBlue?
SendInBlue is a mail service that allows you to send emails from your Node.js application.
Get the Sendinblue email API key
- Go to SendinBlue and create an account.
- Go to Dashboard and click on the top right-hand side dropdown.
- Click on the SMTP & API tab.
- Click on the Create new API key button.
- Now we need to store the api key in an environment variable.
Setup
- Install packages:
npm init -y
npm i dotenv sib-api-v3-sdk
- Create a file called .env and add the following lines:
API_KEY=<your_api_key>
- Create a file called index.js and add the following lines:
const Sib = require('sib-api-v3-sdk')
require('dotenv').config()
const client = Sib.ApiClient.instance
const apiKey = client.authentications['api-key']
apiKey.apiKey = process.env.API_KEY
Explanation: require('dotenv').config(): This is used to load the environment variables from the .env file. Then we have to add the api key to the Sendinblue client.
const tranEmailApi = new Sib.TransactionalEmailsApi()
const sender = {
email: 'thatanjan@gmail.com',
name: 'Anjan',
}
const receivers = [
{
email: '<email address>',
},
]
Explanation: With tranEmailApi we can send emails. The sender email has to be the email account that you have used in the SendinBlue account.
tranEmailApi
.sendTransacEmail({
sender,
to: receivers,
subject: 'Subscribe to Cules Coding to become a developer',
textContent: `
Cules Coding will teach you how to become {{params.role}} a developer.
`,
htmlContent: `
<h1>Cules Coding</h1>
<a href="https://cules-coding.vercel.app/">Visit</a>
`,
params: {
role: 'Frontend',
},
})
.then(console.log)
.catch(console.log)
Explanation:
- You can send emails using the sendTransacEmail method.
- The subject is required.
- You have to pass either textContent or htmlContent to the method. htmlContent will override textContent.
- You can pass parameters to the email content using the params
object. - Run the file and you will see the email was sent.
node index.js
Sendinblue has templates that you can use. If you want me to teach you how to create a newsletter, please let me know. That’s it for today. Have a great day.
How to send emails from Node.js with SendInBlue was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Anjan Shomodder

Anjan Shomodder | Sciencx (2022-05-11T11:23:45+00:00) How to send emails from Node.js with SendInBlue. Retrieved from https://www.scien.cx/2022/05/11/how-to-send-emails-from-node-js-with-sendinblue/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.