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;

知道为什么吗? 预先感谢!

leehomspeed 回答:Angular 7和Node.js中的电子邮件附件

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3117226.html

大家都在问