node.js - Angular 7 和 Node.js 中的电子邮件附件
问题描述
我有一个使用 Angular 7 和 node.js 发送带有附件的电子邮件的联系表格,当您发送带有附件的电子邮件时它工作正常,但没有附件它就不起作用
这是联系表格
打字稿
onSubmitClick() {
const formData: FormData = new FormData();
this.fileToUpload && formData.append("file", this.fileToUpload, this.fileToUpload.name);
for (const key of Object.keys(this.form.value)) {
const value = this.form.value[key];
formData.append(key, value);
}
this.onSubmitClick; {
this.form.reset();
}
this.httpClient.post("http://localhost:3000/api/v1/contact/", formData)
.subscribe((response: any) => console.log(response));
}
handleFileInput(files: FileList) {
this.fileToUpload = files.item(0);
}
}
Node.js 文件
const mailOptions = {
from: 'xxxxxxx@xxx.com',
to: 'xxxxxxx@xxx.com',
subject: 'Segnalazione Portale',
//text: req.body.Nome,
html:'<b>Nome: </b>'+req.body.Nome+
'<br><b>Cognome: </b>'+req.body.Cognome
+'<br><b>Codice Fiscale: </b>'+req.body.CF
+'<br><b>Email: </b>'+req.body.Email
+'<br><b>Messagio: </b>'+req.body.message,
attachments: [
{
filename: file.name,
path: "tmp/" + file.name
}
]
};
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
console.log(err);
return res.json({ err });
} else {
console.log(info);
return res.json({ info });
}
});
});
}
});
module.exports = router;
知道为什么吗?提前致谢!
解决方案
推荐阅读
- itext - Itext Html2pdf 内存管理
- excel - 在 Excel 中有一个带有数据验证的自定义文本列表
- python - Shazam 检测 API 抛出 HTTP 406 Not Acceptable
- java - 使用 KeyFactory 解析公钥
- python - python数据流作业在部署后使用requirements_file参数后不接受来自pubsub订阅的消息
- amazon-web-services - 当我尝试在 AWS Lambda 函数(python)中使用 bash 脚本创建文件时出现错误“只读文件系统”
- c++ - 使用 QProcess 调用带有参数的外部程序
- java - 使用 Android SDK 21 将新文件写入可移动存储中的其他应用程序数据目录时出错
- javascript - Axios 刷新令牌得到 401
- ns-3 - 在 NS3 中执行 Randomwalk2dmobility 时发生错误