0

I am trying to send file using nodemailer text sending is working fine live but when I tried to send file it gives an error live but working fine locally I tried different formats but it still not working

Message: function (req, res) {
    try {
      let body = JSON.parse(req.body.values);    
      var Transport = new nodemailer.createTransport({
        service: "gmail",
        host: "smtp.gmail.com",
        port: 465,
        secure: false,
        auth: {
          user: "email",
          pass: "password",
        },
        
      });

      var mail_options = {
        from: "syeddkrock@gmail.com",
        to: "syedusamatanveer@gmail.com",
        subject: "Details of Client",
        text: `${body.name}`,
        html: `<p>${body.name}${body.email}${body.details}</p>`,  
        attachments: [{   // utf-8 string as an attachment
          filename: req.file.filename,
          contents: 'hello world!'
      },
      {   // utf-8 string as an attachment
          filename:  req.file.filename,
          filePath:  req.file.path
      },]
      };

      new Promise((resolve, reject) => {
        Transport.sendMail(mail_options, function (error, response) {
          if (error) {            
            reject(error);
          } else {
            resolve("email sent");
          }
        });
      });      
    } catch (err) {
      res.json({
        message: err.message,
      });
    }
  },

I am trying to send file using nodemailer text sending is working fine live but when I tried to send file it gives an error live but working fine locally

devpolo
  • 2,487
  • 3
  • 12
  • 28

0 Answers0