Send Email with Attachments in Power Automate(MS Flow)

Introduction: In this blog, we will understand how we can send email with attachments from Power Automate.

  • We will use “Send an Email (V2)” action of Office 365 Outlook connector to send email.

In this blog, I have explained two Use Cases.

  • Use Case 1: Send an email with attachments when an HTTP request is received.
  • Use Case 2:  Send SharePoint Files as attachments in Email.

Implementing Use Case 1: In this example, I am using “When a HTTP request is received” as a trigger and sending an email.

Steps:

  • Select the “When an HTTP request is received” trigger.
  • Enter a sample JSON payload.
{
    "To": "abc@gmail.com;xyz@gmail.com",
    "Subject": "Test email attachment",
    "Body": "Hi, This is test email",
    "Attachment": [
        {
            "Name": "sample.png",
            "ContentBytes": {
                "$content-type": "image/png",
                "$content": "iVBORw0KGgoAAAANSUhEUgAAAHMAAABzCAYAAACrQz3mAAAAAXNSR0IArs4c6QAAAARn/"
            }
        },
        {
            "Name": "Account Overview.pdf",
            "ContentBytes": {
                "$content-type": "application/pdf",
                "$content": "JVBERi0xLjMNCjEgMCBvYmoNClsvUERGIC9UZXh0IC9JbWFnZUIgL0ltYWdlQyAvSW1h"
            }
        }
    ]
}
  • Search for “Office 365 Outlook” and select “Send and email(V2)” action.
  • Enter values in To, Subject and Body from the dynamic content.
  • For Attachments,

– Click on “Switch to input entire array” to pass attachment array

– Enter your attachment array from dynamic content in Attachments.

  • Add Response action to return the response.

Entire Flow:

Testing:

Implementing Use Case 2: In this example, I am getting files from SharePoint and sending them as attachments in an email.

Steps:

  1. Initialize a variable of type Array.
  1. Get all the files which you want to send as attachment in email.
  1. Select “Apply to each” action.
  1. In Apply to each action, pass value of Get files action from the dynamic content.
  1. Add “Get file content” action of SharePoint inside the “Apply to each”.
  • Select your Site Address
  • Enter the File Identifier from the dynamic content.
  1. Add “Append to array variable” action inside the “Apply to each”.
  • In Append to array variable pass the value as shown below.
{
   "Name": "Enter file name with extension from dynamic content",
   "ContentBytes": "Enter file content from dynamic content"
}
  1. Search and select “Send an email (V2)” action.
  • Enter values in To, Subject, and Body.
  • For Attachments,

– Click on “Switch to input entire array” to pass attachment array

– Enter your attachment array variable from dynamic content in Attachments.

Entire Flow:

Testing:

Leave a Reply

Your email address will not be published. Required fields are marked *