I have a contact form that send email with attachment using Angular 7 and node.js, it works fine when you send email with attachment but it doesnt work without attachment
this is contact form
Typescript
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 file
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;
any idea why? thanks in advance!