node.js
In this tutorial, we will learn how we can send email using sendgrid's API and node.js .
As per wikipedia :
SendGrid provides a cloud-based email delivery service that assists businesses with email delivery. The service manages various types of email including shipping notifications, friend requests, sign-up confirmations, and email newsletters. It also handles internet service provider (ISP) monitoring, domain keys, sender policy framework (SPF), and feedback loops. Additionally, the company provides link tracking, open rate reporting.It also allows companies to track email opens, unsubscribes, bounces, and spam reports.Click here to create an account on sendgrid and after that follow the instructions given below :
try for free option for this tutorial as shown below :
Username : This needs to be unique. Password : Enter a secure alphanumeric password here. Confirm password : Enter the password again to confirm it. Email : Enter a valid email address here which you want to link with your sendgrid account. help link
given on the bottom right corner of dashboard as shown below or you can simply click here .
start link provided in front of " Integrate using our Web API or SMTP relay " as shown below :
Web API method for our tutorial which , as per sendgrid ,
is fastest and most flexible way to send email using languages like Node.js, Ruby, C#, and more.
node.js as the language you want to use as shown below :
API key. We can create an API by adding some random content as the name of the
API key and clicking on the create API key button as shown below:
SENDGRID_API_KEY by running the following commands
in your shell :
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
npm install --save @sendgrid/mail
email.js file :
//Name of the file : email.js
// using SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: '[email protected]', //receiver's email
from: '[email protected]', //sender's email
subject: 'I think its working', //Subject
text: 'and finally i can send email from sendgrid', //content
html: 'and easy to do anywhere, even with Node.js', //HTML content
};
sgMail.send(msg);
>node email.js
I've integrated the code above check box and
click on verification button and sendgrid will check whether your mail came through or not.
We learned how we can send a mail using sendgrid.