You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Nodemailing is a lightweight emailing system that takes advantage of SMTP to allow users to easily send emails with no configuration at all.
In fact, all you need do is to require the Nodemailing module and call thesend funtion. Pass your SMTP Host, username, password, recipient, subject, body, and voila! Your messages gets sent immediately.
To get started run
npminstallnodemailing
or go the shorter route
npminodemailing
Now, in your NodeJS project, require Nodemailing.
const{ Nodemailing}=require('nodemailing');
Now, easily send your email
Nodemailing.send({Host://your smtp host,Username://your email,Password://your email password or app password,To://recipient email,From://your email,Subject://email subject,Body://email body,}).then((message)=>//anything goes here....console.log("Email has been sent"));
Tell your recipient to check thier mail, your email just got delivered...!
You Can Also Send Dynamic HTML Email Templates
Create your HTML email template and add the variables you want to modify in{{variable-name}}. Below is a sample.
<div><h1>Welcome to Nodemailing 101</h1><p>Dear {{username}},</p><p> We are so excited to have you here. Nodemailing is a great package and we can be sure you will love it!</p><p> Got any questions as regards this package? You can reach us on GitHub via this username:<strong>{{githubID}}</strong></p></div>
Now that you have your HTML template ready. Call Nodemailingrender function and pass in the path to your HTML template and the data object containing the values for the variables.
// import nodemialingconst{ Nodemailing}=require('nodemailing');// import the path functionconstpath=require('path');// define the path to the HTML templateconstfilePath=path.join(__dirname,'relative/path/to/html/file');// compute the data for the variablesdata={username:'Perfection',githubID:'Samperfect',};// this method uses the await syntax to avoid callback hellasyncfunctioncreateTemp(){// call nodemailing to render the emailconstemailToSend=awaitNodemailing.render(filePath,data);// now call nodemailing to send your mailNodemailing.send({Host:,//your smtp hostUsername:,//your emailPassword:,//your email password or app passwordTo:,//recipient emailFrom:,//your emailSubject:"Welcome Message",Body:emailToSend,}).then((message)=>//anything goes here.... it returns **OK** by defaultconsole.log(message,"Email has been sent")).catch(error=>{// who knows, an error might just occurconsole.log(error)});}// don't forget to call the functioncreateTemp()
And if you prefer to use .then() and .catch(), then you might as well fall into the callback hell below 😎
// import nodemialingconst{ Nodemailing}=require('nodemailing');// import the path functionconstpath=require('path');// define the path to the HTML templateconstfilePath=path.join(__dirname,'relative/path/to/html/file');// compute the data for the variablesdata={username:'Perfection',githubID:'Samperfect',};// call nodemailing to render the emailNodemailing.render(filePath,data).then(emailToSend=>{// now call nodemailing to send your mailNodemailing.send({Host:,//your smtp hostUsername:,//your emailPassword:,//your email password or app passwordTo:,//recipient emailFrom:,//your emailSubject:"Welcome Message",Body:emailToSend,}).then((message)=>//anything goes here.... it returns **OK** by defaultconsole.log(message,"Email has been sent")).catch(error=>{// who knows, an error might just occurconsole.log(error)});}).cath(error=>{console.log(error)});
Tell your recipient to check thier mail, your email just got delivered...!
About
Send emails in NodeJS with no configuration required.