0

I am trying to send email to user using nodemailer module using node.js but it's throwing the below error.

Error:

this.transporter.mailer = this;
                                ^

TypeError: Cannot create property 'mailer' on string 'SMTP'
    at Mail (/opt/lampp/htdocs/heroku/FGDP/node_modules/nodemailer/lib/mailer/index.js:45:33)
    at Object.module.exports.createTransport (/opt/lampp/htdocs/heroku/FGDP/node_modules/nodemailer/lib/nodemailer.js:46:14)
    at Object.<anonymous> (/opt/lampp/htdocs/heroku/FGDP/api/api.js:8:32)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)

Here is my code:

var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "[email protected]",
        pass: "***********"
    }
});

Here I need to send mail to the valid user but getting the above error.

1
  • According to this documentation, the first parameter is an javascript object and not the string "SMTP". Commented Aug 2, 2017 at 8:40

3 Answers 3

2

I think the correct syntax is something like this

var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport({
service: "Gmail",
auth: {
    user: "[email protected]",
    pass: "***********"
}
});
Sign up to request clarification or add additional context in comments.

1 Comment

That was just an example. I meant to say you have to remove the "SMTP". It is not in the nodemailer doc
0
// Use Smtp Protocol to send Email
      var nodemailer = require("nodemailer");
      var smtpTransport = nodemailer.createTransport({
        host: 'smtp.mailgun.org',
        port: 25,
        secure: false, // true for 465, false for other ports
        auth: {
            user: "smtp username", 
            pass: "smtp password" 
        }
      });
      var mail = {
          from: "[email protected]",
          to: "[email protected]",
          subject: "Your subject",
          text: "Node.js New world for me",
          html: "<b>Node.js New world for me</b>"
      }

      smtpTransport.sendMail(mail, function(error, response){
          if(error){
              console.log(error);
          }else{
                //console.log("Message sent: " + response.message);
          }
          smtpTransport.close();
      });

Comments

0

set your nodemailer config like this.

let nodemailerConfig = {
    host:"smtp.gmail.com" ,
    port: 465,
    secure: true, // true for 465, false for other ports
    auth: {
      user: process.env.SMTP_USERNAME,
      pass: process.env.SMTP_PASSWORD
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.