1

如何在 MongoDB 领域运行 nodemailer?nodemailer 无法在 MongoDB Realm 上执行

代码:

    const nodemailer = require("nodemailer");

exports = async function (changeEvent) {
  try {
    const transporter = nodemailer.createTransport({
      service: "gmail",
      auth: {
        user: "somthing@gmail.com",
        pass: "passw0rd",
      },
    });

    let info = transporter.sendMail({
      from: "something@gmail.com",
      to: "wdcjdwzcvpbagtd@frederictonlawyer.com",
      subject: "YesterDay Report Details!",
      html: `
<div style=" text-align: center;" >
    style=" width: 100%; height: 100px; margin-top: 10px;" />
    <br />
    <hr />
    <br />
    <p>
    <span style=" color: rgb(99, 99, 99); font-weight: bold;">
    adminMail </span>, hi there!
     </p>
    
    <br />    
    
    <p style="margin-top: 20px; color: gray;">
    This link expire in 10 minutes</p>
    
    <h5>Total Income Aomunt   : </h5>
    <h5>Avrage Income Aomunt  : </h5>
    <h5>Patientions Count     : </h5>
    <h5>Over-reported Disease : </h5>
    <h5>Reported All Disease  : </h5>
    
    <p>Thanks and Regards</p>
    
    <div style="margin-top: 50px;">&copy; 2021 Apollo</div>
  </div>
`,
    });

    if (info) {
      console.log(info);
    }

    console.log(
      `Successfully send daily report Mail to wdcjdwzcvpbagtd@frederictonlawyer.com :)`
    );
  } catch (err) {
    console.error("Failed to run the function : ", err);
  }
};

输出:

在此处输入图像描述

运行于 2022 年 1 月 13 日星期四 17:33:04 GMT+0530(印度标准时间)错误:无法执行“node_modules/nodemailer/lib/nodemailer.js”的源代码:FunctionError:无法执行“node_modules/nodemailer/”的源代码lib/mailer/index.js': FunctionError: failed to execute source for 'node_modules/nodemailer/lib/shared/index.js': TypeError: 'networkInterfaces' is not a function at node_modules/nodemailer/lib/shared/index. js:41:80(63)

at require (native)
at node_modules/nodemailer/lib/mailer/index.js:37:22(39)

at require (native)
at node_modules/nodemailer/lib/nodemailer.js:13:22(13)

运行于 2022 年 1 月 13 日星期四 17:33:17 GMT+0530(印度标准时间)错误:无法执行“node_modules/nodemailer/lib/nodemailer.js”的源代码:FunctionError:无法执行“node_modules/nodemailer/”的源代码lib/mailer/index.js': FunctionError: failed to execute source for 'node_modules/nodemailer/lib/shared/index.js': TypeError: 'networkInterfaces' is not a function at node_modules/nodemailer/lib/shared/index. js:41:80(63)

at require (native)
at node_modules/nodemailer/lib/mailer/index.js:37:22(39)

at require (native)
at node_modules/nodemailer/lib/nodemailer.js:13:22(13)

但它在我的系统上工作......

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

0

您将需要添加nodemailer为依赖项

Functions屏幕中,您将看到一个 dependencies选项卡。单击它并按照说明添加nodemailer为依赖项。

功能画面

于 2022-01-13T16:04:48.497 回答