# Attaching a local document on email

**URL:** https://discourse.nodered.org/t/attaching-a-local-document-on-email/80803
**Category:** General
**Tags:** function-node
**Created:** [25 August 2023 16:49 UTC](https://discourse.nodered.org/t/attaching-a-local-document-on-email/80803 "2023-08-25T16:49:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sbernabe](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@sbernabe](https://discourse.nodered.org/u/sbernabe)
#### Post date: [25 August 2023 16:49 UTC](https://discourse.nodered.org/t/attaching-a-local-document-on-email/80803/1 "2023-08-25T16:49:11Z")

</div>

This is my code for a function node that sends an email, nowadays it's showing a table on the email. but this information is the same of a local document. The path of my document is D:\POSTMAN\202211300701Energia.csv so I need to attach it.  
This is my actual code:

```auto
//Importante
  //Se reemplaza el Token enviado por el servidor para el proximo envio de email.
  msg.payload.item[0].request.auth.bearer[0].value = msg.keygen;
  
  //Se elimina la variable keygen para no generar problemas en el objeto que se esta creando
  delete msg.keygen;
  
  //Se captura la hora y fecha del sistema y se construye un string para el subject del email
  
  var d = new Date(); // create current date object for the time string
  var tstring = d.toString().substring(0, 4) + d.toString().substring(15, 21);
  
  //Armado del cuerpo del email para el envio de datos a los responsables
  var subjectemail = "Reporte diario de Energia del Sistema de Ventilacion " + tstring; // email subject
  
  var bodyemail = msg.hmtl;
  
  
  //Generacion del cuerpo del Email
  var cadena = {
      "to": {
          "to": [
  
              {
                  "email": "mvalencia@controltotal.com.pe"
              }, {
                  "email": "sbernabe@controltotal.com.pe"
              }
  
  
  
            /* {
                  "email": "mvalencia@controltotal.com.pe"
              }, {
                  "email": "dparedes@controltotal.com.pe"
              },{
                  "email": "jchavez@controltotal.com.pe"
              }*/
          ],
          "cc": [
              /*{
                  "email": "jralejo@controltotal.com.pe"
              }*/
          ],
          "bcc": [
  
          ],
          "replyTo": {
              "email": ""
          }
      },
      "from": {
          "email": "sipddss@mineriabreca.com"
      },
      "files": [
         
      ],
      "subject-mail": subjectemail,
      "content-mail": bodyemail, //Cuerpo del Email
      "sendManager": "1"
  }
  //msg.payload = cadena;
  msg.payload.item[0].request.body.raw = cadena;
  
  
  return msg;

```

So I think that I need to attach this on "files" but I don't know how to attach this propertly

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [25 August 2023 18:02 UTC](https://discourse.nodered.org/t/attaching-a-local-document-on-email/80803/2 "2023-08-25T18:02:18Z")

</div>

You do not say which node you are using.  
I am guessing `node-red-node-email`.  
The read me says

> If the payload is a binary buffer then it will be converted to an attachment.
> 
> The filename should be set using `msg.filename`. Optionally `msg.description` can be added for the body text.
> 
> Alternatively you may provide `msg.attachments` which should contain an array of one or more attachments in [nodemailer](https://nodemailer.com/message/attachments/) format.

---

<div class="post-metadata">

### Author: ![sbernabe](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@sbernabe](https://discourse.nodered.org/u/sbernabe)
#### Post date: [25 August 2023 19:49 UTC](https://discourse.nodered.org/t/attaching-a-local-document-on-email/80803/3 "2023-08-25T19:49:13Z")

</div>

![Screenshot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1bd4d77c0c519f95496137c2bd39976d75bde619.jpeg)  
So this is my flow for sending an email I'm using the function CreateEmail\_string to do my structure of email that I'll send.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [24 October 2023 19:49 UTC](https://discourse.nodered.org/t/attaching-a-local-document-on-email/80803/4 "2023-10-24T19:49:49Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
