AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

Node.js Send Email


<< Previous Page
Nodejs tutorial
Next Page >>
Nodejs tutorial

Node.js Tutorial » Node.js Send Email

How to Send Emails with Node.js

To send emails we use Nodemailer Module

Nodemailer module it is an easy method to send emails from your computer.

Nodemailer module can be downloaded and installed on your server using npm:

E:\Users\Your_Name>npm install nodemailer

After installing nodemailer module, you can check your version in command prompt

E:\Users\Your_Name>npm version nodemailer

After downloaded Nodemailer module, include the module in any application:

var nodemailer = require('nodemailer');

 

Send an Email

After the steps above you are ready to make a web page in Node.js that lets the user send email from your server:

This chapter will show you how to use your Gmail account to send emails:

Example: This code will produce an HTML form:

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'your_email@gmail.com',
pass: 'your_password'
}
});

var mailOptions = {
from: 'your_email@gmail.com',
to: 'my_friend_email@agernic.com',
subject: 'Sending Email using Node.js',
text: 'Hi, this is a text using nodejs send email '
};

transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});

 

Related subjects:
node.js http module node.js upload files global objects nodejs

 

Tags: node js send email with html template, through gmail, without authentification, with attachment, send email without smtp, node js send email smtp example, node js send email through gmail, send email with html template
CAN node JS send emails?
How do I trigger an email in node JS?
How do you use Nodemailer?
How do I send an email from Express?

 

Send Email to Multiple Receivers

To send email to multiple recipients at once, add them to the "to" property of the mailOptions object:

Example: Send email for multiple addresses::
var mailOptions = {
from: 'your_email@gmail.com',
to: 'my_friend1@agernic.com, my_friend2@agernic.com,
my_friend3@agernic.com, my_friend4@agernic.com,',
subject: 'Sending Email using Node.js',
text: 'Hi, this is a test of my nodejs program'
}

 

Send HTML Email

To send HTML formatted text in your email with nodemail module in node, use "html" property instead of the "text" property:

Example Send email with HTML characters:
var mailOptions = {
from: 'youremail@gmail.com',
to: 'my_friend1@agernic.com, my_friend2@agernic.com,
my_friend3@agernic.com, my_friend4@agernic.com,',
subject: 'Sending Email using Node.js',
html: '<h2>Welcome</h2>
<p>Hi, this is a test of my nodejs program</p>
<p>I will see you later</p>
<hr>
Regardes '
}

 



node js send email with html template, through gmail, without authentification, with attachment, send email without smtp, node js send email smtp example, node js send email through gmail, send email with html template
CAN node JS send emails?
How do I trigger an email in node JS?
How do you use Nodemailer?
How do I send an email from Express?

Node.js Send Email - nodejs

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


CSS background color - opacity, gradient...
CSS flex - display: flex - CSS Flexbox L...
CSS border padding...
HTML text center horizontally and vertic...
HTML text input <input type="text"&g...
HTML link color...
How to Link CSS to HTML, external file n...
HTML link - hyperlink...
jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...