Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React nodemailer net.isIP is not a function

I am trying to make a contact page with react and I'm struggling with sending the e-mail part.

I'm trying to use nodemailer, and my code for that is:

var nodemailer = require('nodemailer');
var xoauth2=require('xoauth2');
var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    xoauth2:xoauth2.createXOAuth2Generator({
      user: '[email protected]',
        clientId: '',
        clientSecret: '',
        refreshToken:''
    })
  }
});

var mailOptions = {
  from: 'Name <[email protected]>',
  to: '[email protected]',
  subject: 'Sending Email to test Node.js nodemailer',
  text: 'That was easy to test!'
};

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

I have put the clientId, clientSecret and refreshToken from google API and oauth2 playground and enabled the non secure apps thing. But when I'm trying to send the e-mail I get
TypeError: net.isIP is not a function

EDIT: I have tried adding after service: 'gmail'

type: 'SMTP', host: 'smtp.gmail.com',

Still not working

like image 729
Roland Avatar asked Mar 14 '19 13:03

Roland


1 Answers

I was facing the same issue when trying to implement the nodemailer code client side. The reason was because nodemailer doesn't seem to work in the browser (only in node). Moving it serverside (into an express app) solved the issue.

This post regarding the same error (but affecting a different library) also suggests that running the files in the browser is the problem: http://www.ganzhoupress.com/github_/cypress-io/cypress/issues/1981

Hope this helps.

like image 93
Michael Morrison Avatar answered Nov 17 '22 00:11

Michael Morrison