Angular:Nodemailer显示很多运行时错误 [英] Angular : Nodemailer shows a lot of runtime error

查看:79
本文介绍了Angular:Nodemailer显示很多运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我想使用 Nodemailer 发送邮件.

In my angular project, I want to use Nodemailer to send mail.

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

First problem is when I am trying to import ( i mean after doing npm i --save ) a lot of error occurs when i do ionic serve. I would like to repeat one thing : just after writing the import line, this big error log comes and app crashes like that

错误最像是这种丢失,虽然找不到,但是为什么呢?当我执行npm时,我没有保存任何错误.此外,我的代码中没有语法错误.我唯一的目标是运行sendMail()函数.

errors are most like this missing, that not found but why ? When I did npm i --save there wasn't any error. Besides, I have no syntax error in my code . My only goal is to run the sendMail() function.

我不明白是什么原因引起的?我应该将nodemail更改为其他内容吗?请提出建议.

I just don't get it what causes it? should i change nodemail to something else? please suggest.

错误日志:

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)非常简单

My code (.ts) is very simple

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模块,因此它并不意味着要在浏览器中运行.该模块需要一堆连接对象才能正常工作,而浏览器不允许这样做.因此,最后,您应该有一个可以处理这种事情的后端.

It will never work! As nodemailer is a server-side nodejs module, it's not meant for running inside your browser. The module require a bunch of connectivity objects to work properly which browser doesn't allow it to do so. So, at the end, you should have a backend which handle this kind of stuff.

除了浏览器的连接问题之外,您还有丢失email service凭据的高安全风险!由于angular是客户端框架,因此包含您的电子邮件凭据的客户端可以看到您的代码!这样任何人都可以反编译您的代码&我敢肯定,你偷了.

Apart from the connectivity issues by the browser, you're at high security risk of loosing your email service credentials! Because angular is a client-side framework, your code is visible to the client that contains your email credentials! So anybody can decompile your code & steal which, I'm sure, you don't want.

因此,请尝试将电子邮件逻辑移至后端&既稳定又安全!

So, try moving your email logic to the backend & be stable as well as safe!

这篇关于Angular:Nodemailer显示很多运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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