首页 > 解决方案 > 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;

知道为什么吗?提前致谢!

标签: node.jsangularemailattachment

解决方案


推荐阅读