Attaching a local document on email

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:

//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

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 format.


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.

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