反应nodemailer net.isIP不是一个功能 [英] React nodemailer net.isIP is not a function

查看:342
本文介绍了反应nodemailer net.isIP不是一个功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个带有响应的联系页面,并且我在努力发送电子邮件部分.

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

我正在尝试使用nodemailer,而我的代码是:

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: 'mymail@gmail.com',
        clientId: '',
        clientSecret: '',
        refreshToken:''
    })
  }
});

var mailOptions = {
  from: 'Name <mymail@gmail.com>',
  to: 'mymail@gmail.com',
  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');
  }
});

我已经从Google API和oauth2游乐场中放置了clientIdclientSecretrefreshToken并启用了不安全的应用程序.但是当我尝试发送电子邮件时,我得到了
TypeError:net.isIP不是函数

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

我尝试在service: 'gmail'

类型:"SMTP", 主持人:"smtp.gmail.com",

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

仍然无法正常工作

推荐答案

在尝试实现nodemailer代码客户端时,我面临着同样的问题.原因是因为nodemailer似乎在浏览器中不起作用(仅在node中).将其移至服务器端(移至快速应用程序中)即可解决该问题.

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

希望这会有所帮助.

这篇关于反应nodemailer net.isIP不是一个功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆