Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Send emails in NodeJS with no configuration required.

NotificationsYou must be signed in to change notification settings

opensaucerer/nodemailing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yes! No Configuration Needed

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp