React nodemailer net.isIP 不是一个函数 [英] React nodemailer net.isIP is not a function

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

问题描述

我正在尝试使用 react 制作联系页面,但正在努力发送电子邮件部分.

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');
  }
});

我已经将 clientIdclientSecretrefreshToken 来自 google API 和 oauth2 游乐场并启用了非安全应用程序.但是当我尝试发送电子邮件时,我收到
类型错误: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 似乎在浏览器中不起作用(仅在节点中).将其移动到服务器端(进入快速应用)解决了这个问题.

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.

这篇关于相同错误(但影响不同库)的帖子也表明在浏览器中运行文件是问题所在:http://www.ganzhoupress.com/github_/cypress-io/cypress/issues/1981

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

希望这会有所帮助.

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

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