title: Sending an array of attachments with node.js
body: <p>I need to send an email using nodemailer with several attachments, but the number of those attachments must be defined by the size of an array. I know that nodemailer can send more than one attachment, but I have no idea how to send a variable number of attachments.</p>
  
  <p>Here my code:</p>
  
  <pre><code>  const files = get(req, "body.data.files");
  
    files.forEach(file =&gt; {
     senderMail.send(file, {
      name: get(req, "body.data.files.name"),
      url: get(req, "body.data.files.url")
      });
    });
  
  
     let mailOptions = {
      from: "Me", // 
      sender address
      to: data.personal.user_email, // list of receivers
      subject:
         "An email with attachments"
      text: "someText",
      html: "",
      attachments: [
        {
          filename: name,
          path: url
        }
      ]
    };
  </code></pre>
  
  <p>Some data is obtained from a JSON.</p>