SlideShare a Scribd company logo
How to Set
Up and Send
Mails Using
SendGrid in
NodeJs App?
www.bacancytechnology.com
Introduction
If you have landed on this blog, you know
the purpose of SendGrid and the
importance of sending mail! You might
want to answer questions like What is
SendGrid, and Why use SendGrid? Don’t
worry! We have this covered!


In this tutorial: How to Set Up and Send
Mails using SendGrid in NodeJs App, we will
answer your questions and discuss them
thoroughly! Trust me and read the blog till
the end to know SendGrid inside out!


Also, many developers use a package named
NodeMailer to send emails. You can also
visit the blog: How to Send Email using
NodeMailer with Gmail & Mailtrap, to learn
more about NodeMailer.


Let’s move on then!
Tutorial Goal:
Set Up and
Send Mails
Using
SendGrid in
NodeJs App
I’m new to SendGrid: What is SendGrid?
People appreciating SendGrid: Why use
only SendGrid when you have different
providers?
I’m a technical person. I want to set up
and start using SendGrid with my Node
App: Steps to set up and send emails
using SendGrid in NodeJs app.


Here are your questions and queries! Let’s
have an overview of what our blog has for
you, so you will continue reading till the
end!




Voila! Let’s go!
Our clients say Bacancy
provides the best and
highly-skilled developers!




Want the best? Get the best! Contact
Bacancy and hire Node.js developer for your
dream projects!
What is
SendGrid?
SendGrid is a provider that allows SMTP
(Simple Mail Transfer Protocol) service. I
hope you’re aware of SMTP. It reduces your
time and efforts and provides flexibility
when sending large volumes of emails.
Why use
SendGrid in
NodeJS to
Send Emails?
Powerful email solution for sending
bulk emails with high deliverability
rates
Provides interactive and eye-catching
built-in email templates and freedom to
edit them as well
With the help of SendGrid, you can
track the real-time performance of
emails using various metrics like
bounce rates, unsubscribers, delivered
emails rate, unique reads/opens/clicks,
and many more.
Exceptional customer support
Sendgrid has been integrated with so
many tools that it lets you centralize the
marketing efforts. The API integration
with the various tools is very powerful.
Coming back to our next question, Why
SendGrid with NodeJS? No beating around
the bush, and here are the reasons why you
should use SendGrid for sending emails.
Initial Project
Setup
Create a NodeJs application using the below
command.


mkdir SendgridApp
cd SendgridApp
Initialize Project


npm init -y
It will create a package.json file.


We will install the required dependencies in
our project using the below command.


npm i express @sendgrid/mail dotenv
Open the root file of our project and name it
as your will.


// app.js


const express = require("express");
require("dotenv").config();
var app = express();
app.use(express.json())
const mailRoute =
require('./routes/sendMail')
app.use(mailRoute)
app.listen(process.env.PORT,
console.log('Server is up and running '+
process.env.PORT))
Set Up
SendGrid
Account
Visit SendGrid.com
Create an account
Choose a plan according to your
requirements
Generate API key
Let’s start with integrating Sendgrid.
For setting up the SendGrid account, follow
these instructions-




For sending emails from our NodeJS app, we
need to configure the SendGrid API key in
the application. The SendGrid gives you the
freedom to set up an email as per your
requirement. We can also add and modify
HTML, images, documents, etc.
// email/account.js


const sgMail = require('@sendgrid/mail')
require('dotenv').config()
sgMail.setApiKey(process.env.SENDGRID_
API_KEY) //your sendgrid api key
const sendMail = (email, name) => {
sgMail.send({
To: email, // receiver email address
from: 'fromemail@email.com',
subject: 'here comes subject line',
text: `here comes the body ${name}`
})
}
module.exports = {
sendMail
}
Send Mails
using
SendGrid in
NodeJs App
We can use the sendgrid function wherever
we want to use it, for example, when a user
is registering or leaving or for some other
notifications.


// sendMail.js


For this example, we are sending mail for a
specified route and call sendMail functions
as per our requirement.


const express = require('express')
const { append } =
require('express/lib/response')
const { sendMail } =
require('../emails/accounts')
const statusCode =
require('../constants/constants')
const router = new express.Router()
router.get('/sendmail', (req, res) => {
const user = req.body;
try {
sendMail(user.email,user.name)
res.status(statusCode.ok).send({message:
'Mail Sent'})
} catch (error) {
res.status(statusCode.internalServerError).
send({error})
}
})
module.exports = router
As for this example, we have manually set
the email or other required parameters that
we can send through postman.
Bingo, we sent mail successfully!
Conclusion
I hope the purpose of this tutorial: How to
Set Up and Send Mails using SendGrid in
NodeJS app, was useful to you. If you have
any questions or suggestions, please contact
us and share your thoughts! If you are a
NodeJs enthusiast and willing to polish your
knowledge, then the NodeJS tutorials page
is for you! Don’t waste your time and start
learning more about NodeJS technology!
Are you looking for reliable company to
build your application? Contact Bacancy-
the best Node.js development company and
start working with us!
www.bacancytechnology.com
Thank You

More Related Content

Similar to How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf

Glip team integration with ring central
Glip team integration with ring centralGlip team integration with ring central
Glip team integration with ring central
Khadhar Koneti
 
Frontend APIs powering fast paced product iterations
Frontend APIs powering fast paced product iterationsFrontend APIs powering fast paced product iterations
Frontend APIs powering fast paced product iterations
Karthik Ramgopal
 
BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User Stories
Sauce Labs
 
Vandana_Resume_new
Vandana_Resume_newVandana_Resume_new
Vandana_Resume_new
Vandana Gaikwad
 
Angular 7 Firebase5 CRUD Operations with Reactive Forms
Angular 7 Firebase5 CRUD Operations with Reactive FormsAngular 7 Firebase5 CRUD Operations with Reactive Forms
Angular 7 Firebase5 CRUD Operations with Reactive Forms
Digamber Singh
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
Ksd Che
 
Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB Stitch
MongoDB
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB Stitch
MongoDB
 
How to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using CodeHow to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using Code
Celine George
 
Ajit kumar 18 july (repaired)
Ajit kumar 18 july (repaired)Ajit kumar 18 july (repaired)
Ajit kumar 18 july (repaired)
Ajit kumar
 
Angular js
Angular jsAngular js
Angular js
Thyda Eng
 
ResumeWithPassport
ResumeWithPassportResumeWithPassport
ResumeWithPassport
Sandeep Mukherji
 
Resume
ResumeResume
Resume
Jitu Sahu
 
SwatiNaikResumeAug2016
SwatiNaikResumeAug2016SwatiNaikResumeAug2016
SwatiNaikResumeAug2016
swati Naik
 
Why 2 million Developers depend on MuleSoft
Why 2 million Developers depend on MuleSoftWhy 2 million Developers depend on MuleSoft
Why 2 million Developers depend on MuleSoft
SpringPeople
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
Aishura Aishu
 
How to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet apiHow to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet api
E Boisgontier
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
Visual Engineering
 
unit_tests_tutorial
unit_tests_tutorialunit_tests_tutorial
unit_tests_tutorial
Jonathan (JT) Cho
 
Resume_RahulGhige(1)
Resume_RahulGhige(1)Resume_RahulGhige(1)
Resume_RahulGhige(1)
Rahul Ghige
 

Similar to How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf (20)

Glip team integration with ring central
Glip team integration with ring centralGlip team integration with ring central
Glip team integration with ring central
 
Frontend APIs powering fast paced product iterations
Frontend APIs powering fast paced product iterationsFrontend APIs powering fast paced product iterations
Frontend APIs powering fast paced product iterations
 
BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User Stories
 
Vandana_Resume_new
Vandana_Resume_newVandana_Resume_new
Vandana_Resume_new
 
Angular 7 Firebase5 CRUD Operations with Reactive Forms
Angular 7 Firebase5 CRUD Operations with Reactive FormsAngular 7 Firebase5 CRUD Operations with Reactive Forms
Angular 7 Firebase5 CRUD Operations with Reactive Forms
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB Stitch
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB Stitch
 
How to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using CodeHow to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using Code
 
Ajit kumar 18 july (repaired)
Ajit kumar 18 july (repaired)Ajit kumar 18 july (repaired)
Ajit kumar 18 july (repaired)
 
Angular js
Angular jsAngular js
Angular js
 
ResumeWithPassport
ResumeWithPassportResumeWithPassport
ResumeWithPassport
 
Resume
ResumeResume
Resume
 
SwatiNaikResumeAug2016
SwatiNaikResumeAug2016SwatiNaikResumeAug2016
SwatiNaikResumeAug2016
 
Why 2 million Developers depend on MuleSoft
Why 2 million Developers depend on MuleSoftWhy 2 million Developers depend on MuleSoft
Why 2 million Developers depend on MuleSoft
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
How to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet apiHow to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet api
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
unit_tests_tutorial
unit_tests_tutorialunit_tests_tutorial
unit_tests_tutorial
 
Resume_RahulGhige(1)
Resume_RahulGhige(1)Resume_RahulGhige(1)
Resume_RahulGhige(1)
 

More from Katy Slemon

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Katy Slemon
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
Katy Slemon
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
Katy Slemon
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
Katy Slemon
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
Katy Slemon
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
Katy Slemon
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
Katy Slemon
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
Katy Slemon
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Katy Slemon
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
Katy Slemon
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Katy Slemon
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
Katy Slemon
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
Katy Slemon
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
Katy Slemon
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Katy Slemon
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Katy Slemon
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Katy Slemon
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
Katy Slemon
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
Katy Slemon
 
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdfUncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Katy Slemon
 

More from Katy Slemon (20)

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
 
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdfUncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
 

Recently uploaded

Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Chris Swan
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
Safe Software
 
Best Programming Language for Civil Engineers
Best Programming Language for Civil EngineersBest Programming Language for Civil Engineers
Best Programming Language for Civil Engineers
Awais Yaseen
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
Eric D. Schabell
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
BookNet Canada
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
Mark Billinghurst
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
Matthew Sinclair
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
Neo4j
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
UiPathCommunity
 
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-InTrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 

Recently uploaded (20)

Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
 
Best Programming Language for Civil Engineers
Best Programming Language for Civil EngineersBest Programming Language for Civil Engineers
Best Programming Language for Civil Engineers
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
 
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-InTrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 

How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf

  • 1. How to Set Up and Send Mails Using SendGrid in NodeJs App? www.bacancytechnology.com
  • 3. If you have landed on this blog, you know the purpose of SendGrid and the importance of sending mail! You might want to answer questions like What is SendGrid, and Why use SendGrid? Don’t worry! We have this covered! In this tutorial: How to Set Up and Send Mails using SendGrid in NodeJs App, we will answer your questions and discuss them thoroughly! Trust me and read the blog till the end to know SendGrid inside out! Also, many developers use a package named NodeMailer to send emails. You can also visit the blog: How to Send Email using NodeMailer with Gmail & Mailtrap, to learn more about NodeMailer. Let’s move on then!
  • 4. Tutorial Goal: Set Up and Send Mails Using SendGrid in NodeJs App
  • 5. I’m new to SendGrid: What is SendGrid? People appreciating SendGrid: Why use only SendGrid when you have different providers? I’m a technical person. I want to set up and start using SendGrid with my Node App: Steps to set up and send emails using SendGrid in NodeJs app. Here are your questions and queries! Let’s have an overview of what our blog has for you, so you will continue reading till the end! Voila! Let’s go!
  • 6. Our clients say Bacancy provides the best and highly-skilled developers! Want the best? Get the best! Contact Bacancy and hire Node.js developer for your dream projects!
  • 8. SendGrid is a provider that allows SMTP (Simple Mail Transfer Protocol) service. I hope you’re aware of SMTP. It reduces your time and efforts and provides flexibility when sending large volumes of emails.
  • 9. Why use SendGrid in NodeJS to Send Emails?
  • 10. Powerful email solution for sending bulk emails with high deliverability rates Provides interactive and eye-catching built-in email templates and freedom to edit them as well With the help of SendGrid, you can track the real-time performance of emails using various metrics like bounce rates, unsubscribers, delivered emails rate, unique reads/opens/clicks, and many more. Exceptional customer support Sendgrid has been integrated with so many tools that it lets you centralize the marketing efforts. The API integration with the various tools is very powerful. Coming back to our next question, Why SendGrid with NodeJS? No beating around the bush, and here are the reasons why you should use SendGrid for sending emails.
  • 12. Create a NodeJs application using the below command. mkdir SendgridApp cd SendgridApp Initialize Project npm init -y It will create a package.json file. We will install the required dependencies in our project using the below command. npm i express @sendgrid/mail dotenv
  • 13. Open the root file of our project and name it as your will. // app.js const express = require("express"); require("dotenv").config(); var app = express(); app.use(express.json()) const mailRoute = require('./routes/sendMail') app.use(mailRoute) app.listen(process.env.PORT, console.log('Server is up and running '+ process.env.PORT))
  • 15. Visit SendGrid.com Create an account Choose a plan according to your requirements Generate API key Let’s start with integrating Sendgrid. For setting up the SendGrid account, follow these instructions- For sending emails from our NodeJS app, we need to configure the SendGrid API key in the application. The SendGrid gives you the freedom to set up an email as per your requirement. We can also add and modify HTML, images, documents, etc.
  • 16. // email/account.js const sgMail = require('@sendgrid/mail') require('dotenv').config() sgMail.setApiKey(process.env.SENDGRID_ API_KEY) //your sendgrid api key const sendMail = (email, name) => { sgMail.send({ To: email, // receiver email address from: 'fromemail@email.com', subject: 'here comes subject line', text: `here comes the body ${name}` }) } module.exports = { sendMail }
  • 18. We can use the sendgrid function wherever we want to use it, for example, when a user is registering or leaving or for some other notifications. // sendMail.js For this example, we are sending mail for a specified route and call sendMail functions as per our requirement. const express = require('express') const { append } = require('express/lib/response') const { sendMail } = require('../emails/accounts') const statusCode = require('../constants/constants') const router = new express.Router()
  • 19. router.get('/sendmail', (req, res) => { const user = req.body; try { sendMail(user.email,user.name) res.status(statusCode.ok).send({message: 'Mail Sent'}) } catch (error) { res.status(statusCode.internalServerError). send({error}) } }) module.exports = router As for this example, we have manually set the email or other required parameters that we can send through postman.
  • 20. Bingo, we sent mail successfully!
  • 22. I hope the purpose of this tutorial: How to Set Up and Send Mails using SendGrid in NodeJS app, was useful to you. If you have any questions or suggestions, please contact us and share your thoughts! If you are a NodeJs enthusiast and willing to polish your knowledge, then the NodeJS tutorials page is for you! Don’t waste your time and start learning more about NodeJS technology! Are you looking for reliable company to build your application? Contact Bacancy- the best Node.js development company and start working with us!