简体   繁体   English

Nodemailer 一直给我一个错误:“TypeError [ERR_INVALID_ARG_TYPE]:“chunk”参数必须是字符串类型或......”

[英]Nodemailer keeps giving me an error: "TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or..."

The full error is EXTREMELY long, but here is a snippet:完整的错误非常长,但这里有一个片段:

    TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object
    at PassThrough.Writable.write (_stream_writable.js:289:13)
    at PassThrough.Writable.end (_stream_writable.js:583:10)
    at Immediate._onImmediate (C:\Users\small\desktop\career-change\coding-round-2\portfolio-round1\recipe-app\projectv2\node_modules\nodemailer\lib
\mime-node\index.js:969:46)
    at processImmediate (internal/timers.js:456:21) {
  code: 'ERR_INVALID_ARG_TYPE'
}

This is my first time using nodemailer, or any emailing service for that matter.这是我第一次使用 nodemailer,或者任何电子邮件服务。 I originally started using it with my personal gmail account, then was getting the issue where gmail was blocking it because it was considered a less secure app.我最初是通过我的个人 gmail 帐户开始使用它,然后遇到了 gmail 阻止它的问题,因为它被认为是一个不太安全的应用程序。 So I changed my email settings to allow access from less secure apps.所以我更改了我的 email 设置,以允许从不太安全的应用程序访问。 And then I began getting this error.然后我开始收到这个错误。

I also tried using https://ethereal.email/ to autogenerate an email test account so that I could avoid using gmail, just in case that was the issue.我还尝试使用https://ethereal.email/自动生成 email 测试帐户,这样我就可以避免使用 gmail,以防万一出现问题。

Here is my nodemailer code:这是我的节点邮件程序代码:

const express = require("express");
const router = express.Router();
const bodyParser = require("body-parser");
const nodemailer = require("nodemailer");

router.post("/contact", (req, res) => {
  const output = {
    msg: `You have a new contact request from ${req.body.name}`,
    userEmail: req.body.userEmail,
    subject: req.body.subject,
    message: req.body.message,
  };
  console.log(res);

  // create reusable transporter object using the default SMTP transport
  let transporter = nodemailer.createTransport({
    host: "smtp.ethereal.email",
    port: 587,
    auth: {
      user: "ida.pollich73@ethereal.email",
      pass: "JPtPvputy6n8JBzYe2",
    },
  });

  let mailOptions = {
    from: '"Nodemailer Contact" <mypersonalaccount@gmail.com>', // sender address
    to: "differentpersonalaccount@gmail.com", // list of receivers
    subject: "Node Contact Request", // Subject line
    text: output, // plain text body
    html: output, // html body
  };

  // send mail with defined transport object
  transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
      return console.log(error);
    } else {
      console.log(info);
    }
    res.send("email sent");
    console.log("Message sent: %s", info.messageId);
    // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

    // Preview only available when sending through an Ethereal account
    console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
    // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
  });
});

module.exports = router;

Does anybody have any idea what the error means?有人知道这个错误是什么意思吗? Let me know if you need any more info.如果您需要更多信息,请告诉我。

In my case, i was a trying to send a wrong data type, so i convert the property html to string and was solved.就我而言,我试图发送错误的数据类型,所以我将属性 html 转换为字符串并得到解决。 How i was using next.js, the compiler has reading my html like a JSX element.我是如何使用 next.js 的,编译器像 JSX 元素一样读取了我的 html。

       const mailOptions= {
            from: email,
            to: 'mail@gmail.com',
            subject: `FORMULARIO DE: ${req.body.name}`,
            text: req.body.message,
            html: `<div>${req.body.message}</div>`,
        }

i think the problem is the return.我认为问题是回报。 you must JSON.stringify(error) and get error from sendMail!您必须 JSON.stringify(error) 并从 sendMail 中获取错误!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError [ERR_INVALID_ARG_TYPE]:“块”参数必须是字符串类型或 Buffer 或 Uint8Array 的实例 - TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array TypeError [ERR_INVALID_ARG_TYPE]:“块”参数必须是字符串或缓冲区类型之一。 接收型号 - TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type number TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 收到未定义和代码:'ERR_INVALID_ARG_TYPE' - TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined and code: 'ERR_INVALID_ARG_TYPE' 类型错误 [ERR_INVALID_ARG_TYPE]:“文件”参数必须是字符串类型。 接收类型对象 - TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object Webpack 类型错误&#39;TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 接收类型布尔值(真)&#39; - Webpack type error 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type boolean (true)' 图片上传错误:TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 接收类型未定义 - Image Upload Error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined 将文件固定到 IPFS 时发生错误:TypeError [ERR_INVALID_ARG_TYPE]:“url”参数必须是字符串类型 - Error occurred while pinning file to IPFS: TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 收到 Object 的实例 - TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received an instance of Object TypeError [ERR_INVALID_ARG_TYPE]:“id”参数必须是字符串类型 - TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string 收到此错误 TypeError [ERR_INVALID_ARG_TYPE]: 第一个参数必须是字符串类型或 Buffer 或 Uint8Array 的实例 - Getting this error TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer or Uint8Array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM