0

I'm trying to use Nodemailer for this, but I can't use an attachment in the input, or I don't know how https://nodemailer.com/message/attachments/

please help, anything is helpful for me

postuler.js

let details = {
  name: name.value,
  prenom: prenom.value,
  email: email.value,
  telephone: telephone.value,
  cv: cv.file,
  profil: profil.value,
  motivation: motivation.value
};
let response = await fetch("http://localhost:5000/postuler", {
  method: "POST",
  headers: {
    "Content-Type": "application/json;charset=utf-8",
  },
  body: JSON.stringify(details),
});

server.js

router.post("/postuler", (req, res) => {
const name = req.body.name;
const prenom = req.body.prenom
const email = req.body.email;
const telephone = req.body.telephone;
const cv = req.files;
const profil = req.body.profil;
const motivation = req.body.motivation;


const mail = {
    from: email,
    to: "*************@gmail.com",
    subject: `Contact Form ${name} ${prenom}`,
    html: `<p>Name et Prenom: ${name} ${prenom}</p>
        <p>Email: ${email}</p>
        <p>Telephone: ${telephone}</p>
        <p>Linkedin: ${profil}</p>
        <p>Motivation: ${motivation}</p>
        `,
    attachments: [
        {   // use URL as an attachment
            filename: cv.originalname,
            contentType: 'application/pdf',
            path: cv.path

        },
    ]
};

1 Answers1

0

You tring to send req.file.path as an attachment.

Nodemailer get files as zip , csv,pdf and ect...

Req.file.path it's tricky because the nodemailer don't no where the path is .

Try to zip or save your files in to one file in some folder (you can use fs or js-zip modules) and than give the path of the file as an path in the attachment object.

yanir midler
  • 2,153
  • 1
  • 4
  • 16