Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度:NodeEmailer显示了很多运行时错误_Javascript_Angular_Typescript_Ionic Framework_Nodemailer - Fatal编程技术网

Javascript 角度:NodeEmailer显示了很多运行时错误

Javascript 角度:NodeEmailer显示了很多运行时错误,javascript,angular,typescript,ionic-framework,nodemailer,Javascript,Angular,Typescript,Ionic Framework,Nodemailer,在我的angular项目中,我想使用nodeEmailer发送邮件 第一个问题是,当我尝试导入时(我的意思是在执行npm I--save之后),当我执行ionic service时会发生很多错误。我想重复一件事:在写了导入行之后,这个大错误日志出现了,应用程序就这样崩溃了 错误最像这样缺失,那找不到但为什么呢?当我做npm的时候,我保存没有任何错误。此外,我的代码中没有语法错误。我唯一的目标是运行sendMail()函数 我就是不明白是什么原因?我是否应该将nodemail更改为其他内容?请建

在我的angular项目中,我想使用nodeEmailer发送邮件

第一个问题是,当我尝试导入时(我的意思是在执行npm I--save之后),当我执行
ionic service
时会发生很多错误。我想重复一件事:在写了导入行之后,这个大错误日志出现了,应用程序就这样崩溃了

错误最像这样缺失,那找不到但为什么呢?当我做npm的时候,我保存没有任何错误。此外,我的代码中没有语法错误。我唯一的目标是运行
sendMail()
函数

我就是不明白是什么原因?我是否应该将
nodemail
更改为其他内容?请建议

错误日志:

Microsoft Windows [Version 10.0.19041.264]
(c) 2020 Microsoft Corporation. All rights reserved.

C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master>ionic serve
> ng.cmd run app:serve --host=localhost --port=8100
[ng] chunk {} 0.js, 0.js.map () 31.1 kB  [rendered]
[ng] ERROR in ./node_modules/nodemailer/lib/sendmail-transport/index.js
[ng] Module not found: Error: Can't resolve 'child_process' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\sendmail-transport'
[ng] ERROR in ./node_modules/nodemailer/lib/dkim/index.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\dkim'
[ng] ERROR in ./node_modules/nodemailer/lib/dkim/sign.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\dkim'
[ng] ERROR in ./node_modules/nodemailer/lib/dkim/relaxed-body.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\dkim'
[ng] ERROR in ./node_modules/nodemailer/lib/mailer/index.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mailer'
[ng] ERROR in ./node_modules/nodemailer/lib/mime-node/index.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mime-node'
[ng] ERROR in ./node_modules/nodemailer/lib/smtp-connection/index.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\smtp-connection'
[ng] ERROR in ./node_modules/nodemailer/lib/xoauth2/index.js
[ng] Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\xoauth2'
[ng] ERROR in ./node_modules/nodemailer/lib/mailer/index.js
[ng] Module not found: Error: Can't resolve 'dns' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mailer'
[ng] ERROR in ./node_modules/nodemailer/lib/shared/index.js
[ng] Module not found: Error: Can't resolve 'dns' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\shared'
[ng] ERROR in ./node_modules/nodemailer/lib/dkim/index.js
[ng] Module not found: Error: Can't resolve 'fs' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\dkim'
[ng] ERROR in ./node_modules/nodemailer/lib/mime-node/index.js
[ng] Module not found: Error: Can't resolve 'fs' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mime-node'
[ng] ERROR in ./node_modules/nodemailer/lib/shared/index.js
[ng] Module not found: Error: Can't resolve 'fs' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\shared'
[ng] ERROR in ./node_modules/nodemailer/lib/fetch/index.js
[ng] Module not found: Error: Can't resolve 'http' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\fetch'
[ng] ERROR in ./node_modules/nodemailer/lib/fetch/index.js
[ng] Module not found: Error: Can't resolve 'https' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\fetch'
[ng] ERROR in ./node_modules/nodemailer/lib/mailer/index.js
[ng] Module not found: Error: Can't resolve 'net' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mailer'
[ng] ERROR in ./node_modules/nodemailer/lib/shared/index.js
[ng] Module not found: Error: Can't resolve 'net' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\shared'
[ng] ERROR in ./node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js
[ng] Module not found: Error: Can't resolve 'net' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\smtp-connection'
[ng] ERROR in ./node_modules/nodemailer/lib/smtp-connection/index.js
[ng] Module not found: Error: Can't resolve 'net' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\smtp-connection'
[ng] ERROR in ./node_modules/nodemailer/lib/mime-node/index.js
[ng] Module not found: Error: Can't resolve 'os' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mime-node'
[ng] ERROR in ./node_modules/nodemailer/lib/smtp-connection/index.js
[ng] Module not found: Error: Can't resolve 'os' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\smtp-connection'
[ng] ERROR in ./node_modules/nodemailer/lib/dkim/index.js
[ng] Module not found: Error: Can't resolve 'path' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\dkim'
[ng] ERROR in ./node_modules/nodemailer/lib/mime-funcs/mime-types.js
[ng] Module not found: Error: Can't resolve 'path' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mime-funcs'
[ng] ERROR in ./node_modules/nodemailer/lib/base64/index.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\base64'
[ng] ERROR in ./node_modules/nodemailer/lib/dkim/index.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\dkim'
[ng] ERROR in ./node_modules/nodemailer/lib/dkim/message-parser.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\dkim'
[ng] ERROR in ./node_modules/nodemailer/lib/dkim/relaxed-body.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\dkim'
[ng] ERROR in ./node_modules/nodemailer/lib/fetch/index.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\fetch'
[ng] ERROR in ./node_modules/nodemailer/lib/mime-node/index.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mime-node'
[ng] ERROR in ./node_modules/nodemailer/lib/mime-node/last-newline.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\mime-node'
[ng] ERROR in ./node_modules/nodemailer/lib/qp/index.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\qp'
[ng] ERROR in ./node_modules/nodemailer/lib/sendmail-transport/le-unix.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\sendmail-transport'
[ng] ERROR in ./node_modules/nodemailer/lib/sendmail-transport/le-windows.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\sendmail-transport'
[ng] ERROR in ./node_modules/nodemailer/lib/smtp-connection/index.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\smtp-connection'
[ng] ERROR in ./node_modules/nodemailer/lib/smtp-connection/data-stream.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\smtp-connection'
[ng] ERROR in ./node_modules/nodemailer/lib/xoauth2/index.js
[ng] Module not found: Error: Can't resolve 'stream' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\xoauth2'
[ng] ERROR in ./node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js
[ng] Module not found: Error: Can't resolve 'tls' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\smtp-connection'
[ng] ERROR in ./node_modules/nodemailer/lib/smtp-connection/index.js
[ng] Module not found: Error: Can't resolve 'tls' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\smtp-connection'
[ng] ERROR in ./node_modules/nodemailer/lib/fetch/index.js
[ng] Module not found: Error: Can't resolve 'zlib' in 'C:\Users\Admin\Desktop\ionic\ionic-project-1-login-and-nested-list-and-report-modal-master\node_modules\nodemailer\lib\fetch'
[ng] chunk {common} common.js, common.js.map (common) 26.2 kB  [rendered]
[ng] chunk {focus-visible-15ada7f7-js} focus-visible-15ada7f7-js.js, focus-visible-15ada7f7-js.js.map (focus-visible-15ada7f7-js) 2.11 kB  [rendered]
[ng] chunk {input-shims-d4609e0d-js} input-shims-d4609e0d-js.js, input-shims-d4609e0d-js.js.map (input-shims-d4609e0d-js) 15.3 kB  [rendered]
[ng] chunk {keyboard-a2b5e51d-js} keyboard-a2b5e51d-js.js, keyboard-a2b5e51d-js.js.map (keyboard-a2b5e51d-js) 7.28 kB  [rendered]
[ng] chunk {login-login-module} login-login-module.js, login-login-module.js.map (login-login-module) 14 kB  [rendered] 
[ng] chunk {main} main.js, main.js.map (main) 25.9 kB [initial] [rendered]
[ng] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 268 kB [initial] [rendered]
[ng] chunk {polyfills-core-js} polyfills-core-js.js, polyfills-core-js.js.map (polyfills-core-js) 78.7 kB  [rendered]   
[ng] chunk {polyfills-css-shim} polyfills-css-shim.js, polyfills-css-shim.js.map (polyfills-css-shim) 10.5 kB  [rendered]
[ng] chunk {polyfills-dom} polyfills-dom.js, polyfills-dom.js.map (polyfills-dom) 38.5 kB  [rendered]
[ng] chunk {product-list-product-list-module} product-list-product-list-module.js, product-list-product-list-module.js.map (product-list-product-list-module) 17.4 kB  [rendered]
[ng] chunk {reset-password-one-reset-password-one-module} reset-password-one-reset-password-one-module.js, reset-password-one-reset-password-one-module.js.map (reset-password-one-reset-password-one-module) 489 kB  [rendered]
[ng] chunk {runtime} runtime.js, runtime.js.map (runtime) 9.82 kB [entry] [rendered]
[ng] chunk {shadow-css-7f9c6860-js} shadow-css-7f9c6860-js.js, shadow-css-7f9c6860-js.js.map (shadow-css-7f9c6860-js) 15.9 kB  [rendered]
[ng] chunk {signup-signup-module} signup-signup-module.js, signup-signup-module.js.map (signup-signup-module) 16 kB  [rendered]
[ng] chunk {status-tap-171795fe-js} status-tap-171795fe-js.js, status-tap-171795fe-js.js.map (status-tap-171795fe-js) 1.6 kB  [rendered]
[ng] chunk {stock-modal-one-stock-modal-one-module} stock-modal-one-stock-modal-one-module.js, stock-modal-one-stock-modal-one-module.js.map (stock-modal-one-stock-modal-one-module) 4.55 kB  [rendered]
[ng] chunk {styles} styles.js, styles.js.map (styles) 100 kB [initial] [rendered]
[ng] chunk {swipe-back-0a6a44c8-js} swipe-back-0a6a44c8-js.js, swipe-back-0a6a44c8-js.js.map (swipe-back-0a6a44c8-js) 3.05 kB  [rendered]
[ng] chunk {swiper-bundle-e8f38f34-js} swiper-bundle-e8f38f34-js.js, swiper-bundle-e8f38f34-js.js.map (swiper-bundle-e8f38f34-js) 196 kB  [rendered]
[ng] chunk {tap-click-252af35a-js} tap-click-252af35a-js.js, tap-click-252af35a-js.js.map (tap-click-252af35a-js) 6.22 kB  [rendered]
[ng] chunk {vendor} vendor.js, vendor.js.map (vendor) 5.25 MB [initial] [rendered]
[ng] Date: 2020-07-13T15:07:18.475Z - Hash: fd07469b5de5766cdb0b - Time: 14159ms

[INFO] Development server running!

       Local: http://localhost:8100

       Use Ctrl+C to quit this process

[INFO] Browser window opened to http://localhost:8100!

[ng] Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\DumpStack.log.tmp'
[ng] Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\hiberfil.sys'
[ng] Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\pagefile.sys'
[ng] Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\swapfile.sys'
我的代码(.ts)非常简单

import { Component, OnInit } from '@angular/core';

import * as nodemailer from 'nodemailer';
@Component({
  selector: 'app-reset-password-one',
  templateUrl: './reset-password-one.page.html',
  styleUrls: ['./reset-password-one.page.scss'],
})
export class ResetPasswordOnePage implements OnInit {

  emailTo = '';


  // create expiration date

  constructor() { }

  ngOnInit() {
  }

  sendVerification() {
    // this.getToken();
    this.sendMail();

  }

  getToken() {
    //create random 16 character token
    var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var token = '';
    for (var i = 16; i > 0; --i) {
      token += chars[Math.round(Math.random() * (chars.length - 1))];
    }
    console.log(token);
    return token;
  }

  sendMail() {

    var transporter = nodemailer.createTransport({
      service: 'gmail',
      auth: {
        user: 'youremail@gmail.com',
        pass: 'yourpassword'
      }
    });

    var mailOptions = {
      from: 'youremail@gmail.com',
      to: 'myfriend@yahoo.com',
      subject: 'Sending Email using Node.js',
      text: 'That was easy!'
    };

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

  }

}

这是行不通的!由于
nodemailer
是一个服务器端
nodejs
模块,它不适合在浏览器中运行。该模块需要一组连接对象才能正常工作,而浏览器不允许这样做。所以,最后,你应该有一个后端来处理这类东西

除了浏览器的连接问题外,您还面临着丢失
电子邮件服务
凭据的高安全风险!由于
angular
是一个客户端框架,因此包含电子邮件凭据的客户端可以看到您的代码!所以任何人都可以反编译你的代码&我敢肯定,这是你不想要的


因此,尝试将您的电子邮件逻辑移动到后端&既稳定又安全

当然不行了。您正在尝试直接从浏览器发送邮件。这应该发生在服务器端。NodeEmailer是一个Node.js模块,它不应该在浏览器中运行。你不能用Angular直接发送消息。它是一个前端框架,即在客户端工作。电子邮件发送功能是服务器端的东西。因此,您最有可能拥有一个后端,从您的Angular应用程序获取发送消息的请求。取自@AshutoshKumar,假设我的cilent端生成一个代码230。我想把它发送到用户输入的电子邮件。现在,如果我制作一个节点js后端,如何将230从前端发送到后端?(然后我需要发送邮件)@Frost通过
HTTP请求将此数据发送到您的后端
&尝试在那里发送邮件!