![]()
In this โPower Automate create CSV file and send email attachmentโ article, we will learn using Power Automate how to create a CSV file and how to send an email with the attachments.
Business Use Cases: Using Power Automate create CSV file and send email with attachment in Power Automate
There are many use-cases for this requirement, for this demo, we have highlighted the below two:
Use Case 1: Checked Out Files report
Many times, we can see that a lot of files in the SharePoint Online document library will be in the โchecked outโ state. If you want those files to be checked in by the owner of the document, you can develop a manually executed or scheduler-type Power Automate flow that will query your document library and prepare the checked-out file report.
A copy of this file you can store in a report document library, and you can send one more copy of the file to the concerned person. In the demo, we will show this.
Use Case 2: Approved files report
Suppose you have a document library with thousands of documents where there is a column for document status with the value โDraft and Approvedโ. If you want to send all approved files to your manager as email attachments, you can develop a manually executed or scheduler-type Power Automate flow that will query your document library and prepare the approved file report.
Then, you can send all the approved files as email attachments automatically to your manager. In the demo, we will show this.
Complete Flow: Using Power Automate create CSV file and send email with attachment in Power Automate
Below is the complete Power Automate flow that creates a CSV file and sends an email with an attachment:

Flow Explanation: Using Power Automate create CSV file and send email with attachment in Power Automate
In this section, we will explain the flow step by step.
Step 1: Variable initialization
Create the following two variables:
- varFileAttachments: Type of Array
- varAttahmentmentFileName: A string with the following default value: @concat(โChecked Out Files Report,โ utcNow(), โ.csvโ)

Step 2: Get checked out files from SharePoint Online document library
Add a โGet files (properties only)โ action. To filter the checked-out files, add the below filter query:
CheckoutUserId Does not equal null

Note:
- For your scenario, you can filter using any other criteria.
Step 3: Select data operation to map the needed columns
Add a select data operation to map the needed columns. Enter the following in the โFromโ field:
@{outputs('Get_files_(properties_only)')?['body/value']}

Step 5: Create a CSV table
Add a create CSV table data operation, and in the from field, pass the output of the previous โSelectโ step as below:
@{body('Select')}

Step 6: Create a CSV file in SharePoint document library
Add a Create File action and pass the site address and folder path.
In the file name, pass the variable โvarAttahmentmentFileNameโ (select from the dynamic value tab).
In the File Content, pass the output of โCreate CSV tableโ (select from the dynamic value tab).

The above โCreate fileโ action will create a CSV file in the โShared Documentsโ library.
Step 7: Get file content from the newly created file
Add a โGet file contentโ action and pass the site address and file identifier.
Select the file ID from the create file action (from the dynamic value tab).

Step 8: Add data to array variable collection for the email attachment
Add an โAppend to array variableโ action and pass the below parameters:
- Name: Select the File Name variable (โvarAttahmentmentFileNameโ).
- ContentBytes: Body of Get file content (select the file content from the dynamic value tab).

Below is the syntax to pass the value to array variable for the file attachment functionality in the email.
{
"Name": "Pass the file name with extension from dynamic content or you can pass your own custom file name",
"ContentBytes": "Pass the file content from get file content (dynamic value tab)"
}
Step 9: Add send email action (V2/V3) to send the attachment in the email
Add a โSend an email (V2/V3)โ action and the below parameters:
- To: Your email address
- Subject: A meaningful text
- Body: A meaningful paragraph
- Attachments: Select the attachment variable (โvarFileAttachmentsโ) from the dynamic value tab.

Note:
- You can pass more than one attachment file.
Step 10: Demo โ Checked out files report
Now, if you execute the flow, you can see that a โChecked Out Files Report CSVโ has been created in the โDocumentsโ library.

Note:
- As we have executed the flow a couple of times, multiple files are created.
ย
At the same time, we can see that one email has arrived in your inbox with the checked-out files report as an attachment.

Use Case 2 (Approved Files): Send email with attachment in Power Automate
In this section, we will learn how to get all approved files from a document library and send those files as email attachments.
Step 1: Get all approved files from SharePoint Online document library
Add a โGet files (properties only)โ action and pass the site address and library name as the parameters.
In the filter query, add the following:
DocumentStatus equals approved
Using Power Automate, retrieve all approved files from the SharePoint Online Document Library.
ย
Note:
- For this demo, we have filtered the document library by the document status column. However, for your scenario, you can filter with some other criteria.
Step 2: Send email attachments with files from the SharePoint document library
Add an โApply to eachโ control.
Enter the following value in the Select an output from Steps column:
@{outputs('Get_files_(properties_only)_-_Get_Approved_Files')?['body/value']}
Inside the loop, perform the following:
Add a โGet file contentโ action where you pass the site address and file identifier. The file identifier should be selected from the โget file properties onlyโ (approved files) action.
Add an โAppend to array variableโ data operation and pass the below parameters:
- Name: Select โvarFileAttachmentsโ from the dynamic value variables section.
- For the value, pass the following:
{
"Name": "@{items('Apply_to_each')?['{FilenameWithExtension}']}",
"ContentBytes": "@{body('Get_file_content_2')}"
}
Send email attachments with files from SharePoint document library using Power Automate
ย
Finally, outside of the apply to each control, add a โSend an emailโ action with the following parameters:
- Your e-mail address
- Subject: A meaningful text
- Body: A meaningful paragraph
- Attachments: Select the attachment variable (โvarFileAttachmentsโ) from the dynamic value tab.
Send email attachments with files from the SharePoint document library using Power Automate.
Step 3 (Approved Files) Demo: Send email with attachment in Power Automate
Navigate to your document library and filter by the document typeโs approved status value.

Now, if you execute the flow, you can see that all the approved files from the document library have arrived in your mailbox as attachments.

Summary: Using Power Automate create CSV file and send email with attachment using Power Automate
Thus, in this article, we have learned the following with respect to sending email attachments using Power Automate:
- How to create a CSV file in SharePoint Onlineโs document library using Power Automate
- How to send a CSV file as an email attachment using Power Automate
- How to send all files from your document library as email attachments using Power Automate
- How to use Get file content in Power Automate
- How to create a CSV file using Power Automate
- How to loop through each files in SharePoint using apply to each control
- How to use append to array variable in Power Automate
See Also: Power Automate Tutorials
- You may visit theย Power Automate articles hub
- Take care of whatโs important. Automate the rest
If you like our articles, please appreciate our efforts by liking and sharing them with your friends and colleagues. Please join the mailing list to get our articles in your inbox as and when we publish them.
Happy automating and learning!
About Post Author
Discover more from Global SharePoint
Subscribe to get the latest posts sent to your email.




