Integrating Twilio SMS and SendGrid Email API using node.js

12-02-2019    Hari Kondlapudi    Views 1480

Twilio has democratized communications channels like voice, text, chat, video, and email by virtualizing the world's communications infrastructure through APIs that are simple enough for any developer to use, yet robust enough to power the world's most demanding applications.

Twilio SMS:

Twilio's SMS API helps you add robust messaging capability to your applications. Using this Rest API, you can send SMS messages, track the delivery of sent messages. When you create an account in Twilio, you get a Twilio Phone number, Account SID and Auth Token. 

To send your SMS (Node.js), you need to have Installed Node.js and Twilio Node.js module. After installing Node.js in your device.
To install the Twilio Node library using npm, run the following command in your terminal.

 npm install twilio

I have saved the below code in the sendSms.js file, enter node sendSms.js in your terminal to run the file.

// Twilio Credentials
// require the Twilio module and create a REST client
const client = require('twilio')(accountSid, authToken);
function sendSMS() {
       body: 'Hello',//write the message you want to send.
       from: '+1xxxxxxxxxx',// place your Twilio phone number here.
       to:'+91xxxxxxxxxx' //place phone number you want to send.
      (err, result) => {
         if (err) {
         } else {


apiVersion: '2010-04-01',
body: 'Sent from your Twilio trial account - Hello',
dateCreated: 2020-09-08T02:05:59.000Z,
dateUpdated: 2020-09-08T02:05:59.000Z,
dateSent: null,
direction: 'outbound-api',
errorCode: null,
errorMessage: null,
from: '+1xxxxxxxxxx',
messagingServiceSid: null,
numMedia: '0',
numSegments: '1',
price: null,
priceUnit: 'USD',
sid: 'SM772756f57ace40d580ede84cc2dd6ddc',
status: 'queued',
media:   '/2010-04- 01/Accounts/AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SM772756f57ace40d580ede84cc2dd6ddc/Media.json' },
to: '+91xxxxxxxxxx',
 '/2010-04-01/Accounts/AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SM772756f57ace40d580ede84cc2dd6ddc.json' }

When you send an SMS from your free trial phone number,as you can see in the result text in SMS, it always begins with “Sent from a Twilio trial account.” This message will be removed after you upgrade your account. While in trial mode,you can only send  SMS to non-Twilio phone numbers you’ve verified with Twilio.

Twilio SendGrid Email:

SendGrid is a cloud-based SMTP provider that allows you to send email without having to maintain email servers. SendGrid manages all of the technical details, from scaling the infrastructure to ISP outreach and real-time analytics. It also provides Dynamic Templates, Email validation, and Email testing. When you create an account in SendGrid, you get a secret unique API key.

To send an Email  (Node.js), you need to have Installed Node.js and SendGrid Node.js module. Install Node.js in your device.
To install the SendGrid Node library using npm, run the following command in your terminal.

npm i sendgrid

I have saved the below code in sendEmail.js file,enter node sendEmail.js in your terminal to run the file.

import sgMail from '@sendgrid/mail';
 function send() {
let sendGridApiKey = "SG.xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 let body= {
       to:””, //Email ID, you want to send mail.
       subject:”Testing Email”, //Subject of your Mail.
       html: '', //write your own Template.
      from: ”” //Email ID.
         sgMail.send(body, (err) => {
         if (err) {
           console.log('Error', err);
         } else {
           console.log("Email send successfully")

Subscribe to Email Updates


Add Comments

Submit Comments

More Blogs

What is Trade Finance Transaction?

Blockchain Technology In Trade Finance Transactions

Hari Kondlapudi        Views 2297

Blockchain to transform your business

Hari Kondlapudi        Views 2175

Localization with React

Hari Kondlapudi        Views 1335

Contact Us

US Address:

Do Systems Inc,
433 Plaza Real, Suite 275
Boca Raton, FL 33432 

India Address:

Jayeesha Software Pvt Ltd
Hitech City Rd, VIP Hills,
Silicon Valley, Madhapur,
Hyderabad, TS 500081



Copyright © 2023 Do Systems Inc. All rights reserved. Privacy Policy