Search code examples
azurepower-automate

Power Automate convert csv file to EML format


I am trying to create a flow in Power Automate which reads a csv file from azure blob and convert it to EML format as defined by RFC 2822 then attach that to email and send to a recipient.

The part that I am stuck at is creating the eml wrapper once I read the content of the file

Is there any action in power automate flow that can do this?

enter image description here


Solution

  • I do agree with @Skin, Alternatively, I would suggest you to Azure Logic apps and you can use below approach:

    Design:

    Here I taken CSV data directly, you can take it from Azure Blob storage:

    enter image description here

    JavaScript Code:

    const rithcsv =workflowContext.actions.Compose.outputs;
    const rows = rithcsv.trim().split('\n').map(row => row.split(','));
    const headers = rows.shift();
    const data = rows.map(row => {
      const rithobj = {};
      headers.forEach((header, i) => rithobj[header] = row[i]);
      return rithobj;
    });
    const ritheml = `
    ${data.map(row => `${row.Test} ${row.Body} ${row.OtherField}`).join('\n')}
    `;
    return ritheml;
    

    Then:

    enter image description here

    Output:

    enter image description here