A
A
Alexander Koshelev2018-05-30 20:56:20
Node.js
Alexander Koshelev, 2018-05-30 20:56:20

Why does the nodemailer npm module throw an error when sending?

Good evening everyone!
Dear friends, please tell me what is the problem?
created a file with the code, installed nodemailer, did everything necessary to get the id, secret, token and inserted it into the right places in the code. I get an error on startup, what could be the problem?
here is the code

const nodemailer = require('nodemailer');
const xoauth2 = require('xoauth2');

var transporter = nodemailer.createTransport({
  service: "gmail",
  auth: {
    xoauth2: xoauth2.createXOAuth2Generator({
      user: 'моя почта',
      clientId: "мой клиент айди",
      clientSecret: "мой секрет",
      refreshToken: "рефреш токен"
    })
  }
});

var mailOptions = {
  from: "Alex <моя почта>",
  to: "почта куда отправляется",
  subject: "Nodemailer test",
  text: "Hi Max"
};

transporter.sendMail(mailOptions, function(err, res){
  if(err){
    console.log("Ошибка");
  } else{
    console.log("Письмо ушло");
  }
})

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question