首页 > 解决方案 > “Content-Type”在 JavaScript 中显示了意外的标记

问题描述

我正在使用 SMTP 从我的 ReactJS 应用程序发送 ZIP 文件。我可以将 PNG 图像作为附件发送,而无需将任何“Content-Type”指定为 SMTP 属性。

但是当我添加Content-Type : "application/octet-stream"用于发送 zip 文件时,它会在 "-" 处显示 Unexpected token

我应该用什么替换它来发送 zip 文件?

这是我的 SMTP 连接代码;

sendEmail = (url, filename)=> {
      Email.send({
      Host: "smtp.gmail.com",

      Content-Type : "application/octet-stream",

      Username : "xxxxx@gmail.com",
      Password : "xxxxxxxxxxxxxx",
      To : 'xxxxxxx@gmail.com',
      From : "xxxxx@gmail.com",
      Subject : "Your file is ready! ",
      Body : "Body of the Email",
      Attachments : [
        {
            name : filename,
            path : url
        }]
      }).then(
        message => alert("Mail Sent")
      );
    }

这就是它呈现的内容;
输出图像

标签: reactjssmtpzipattachmentcontent-type

解决方案


尝试将 Content-Type 替换为“Content-Type”。像这样

Email.send({
      Host: "smtp.gmail.com",
      "Content-Type" : "application/octet-stream",
      Username : "xxxxx@gmail.com",
      Password : "xxxxxxxxxxxxxx",
      To : 'xxxxxxx@gmail.com',
      From : "xxxxx@gmail.com",
      Subject : "Your file is ready! ",
      Body : "Body of the Email",

推荐阅读