Jalodara Jayesh
Jalodara Jayesh

Reputation: 327

Can not connect SMTP Server In node JS Local server using Google account

I was not able to connect to SMTP Server In node JS Local server using Google account. i have tried my local server for sending mail using google but i encountered these errors. How can i solve this?

Here was my code :

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

var mailOptions = {
      from: '****@gmail.com',
      to: '******@gmail.com',
      subject: 'Sending Email using Node.js',
      text: 'That was easy!'
    };  

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

Error

Error: Cannot find module 'nodemailer'
    at Function.Module._resolveFilename internal/modules/cjs/loader.js:581:15)

    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/home/dev5_etech/socket/app.js:4:18)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

Upvotes: 1

Views: 737

Answers (2)

user11926591
user11926591

Reputation:

Using single line command you will install nodemailer package.

npm install --g nodemailer --save

Upvotes: 2

user11868862
user11868862

Reputation:

@jayesh

first npm -g install nodemailer

then npm install nodemailer --save

Than after you can see in your package.json file is the

"name": "appication name",
"description": "...",
"version": "0.0.3",
"dependencies": {
"express": "^4.17.1",
  "nodemon": "^1.19.1",
  "socket.io": "^2.2.0"
  "nodemailer":"^0.4.0"
}

If you try and run as per this command and solve you problem.

Upvotes: 1

Related Questions