reactjs - “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")
);
}
这就是它呈现的内容;
输出图像
解决方案
尝试将 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",
推荐阅读
- php - 添加 Joomla!文章的自定义字段
- kubernetes - RabbitMQ 和 Kubernetes
- ruby-on-rails - 如何在 Rails 5.2 中通过 has_many 预加载 has_one?
- python - 如何创建具有时间重叠的邻接矩阵?
- mysql - s3 密钥最接近的 mysql 类型是什么?
- java - Tomcat 找不到 gson 库(通过 maven 包含)
- delphi - Delphi TJvDBGrid 保存布局
- performance - 如何在图像上并行化相同且独立应用的代码(每个核心均匀分布图像)(目标:加速)
- spring-data-jdbc - 使用 Spring Data JDBC 的嵌套数据结构
- elasticsearch - 从查询中删除停用词