Automate Email with Azure Logic App

Automation with playbook

Featured image

Before start,let’s understand the usecase of Logic App and our requirements.

We need to create an automated email flow with attachment with particular email group or people. So for this we need to create a logic app with storage account which contains our email attachment. Now let’s divide it into 2 parts

  1. Storage account creation
  2. Logic App

Requirements :-

  1. Azure Subscription
  2. Storage Account access
  3. Logic App contributor access
  4. Email group either outlook or gmail

Steps :-

Image

image

Image

Image

Image

Storage and Container creation

Image

image

image

we’ll be using upload feature to upload attachment there and logic app will fetch it out.

Now jump over 2nd part i.e

Logic APP creation

image

Image

Image

image

Image

Image

Image

Immage

Image

Image

Code Snippet : Logic App


{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Get_blob_content_(V2)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob_1']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent('/email/',triggerBody()?['Name']))}/content"
                },
                "runAfter": {},
                "type": "ApiConnection"
            },
            "Send_an_email_(V2)": {
                "inputs": {
                    "body": {
                        "Attachments": [
                            {
                                "ContentBytes": "@{base64(body('Get_blob_content_(V2)'))}",
                                "Name": "@triggerBody()?['Name']"
                            }
                        ],
                        "Body": "<p>Hello ,<br>\n<br>\nThis is automated mail from the &nbsp;Azure logic app</p>",
                        "Subject": "Auto Mail from Logic App ",
                        "To": "shubhendushubham98@gmail.com"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/v2/Mail"
                },
                "runAfter": {
                    "Get_blob_content_(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_blob_is_added_or_modified_(properties_only)_(V2)": {
                "evaluatedRecurrence": {
                    "frequency": "Second",
                    "interval": 5
                },
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob_1']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/triggers/batch/onupdatedfile",
                    "queries": {
                        "checkBothCreatedAndModifiedDateTime": false,
                        "folderId": "JTJmZW1haWw=",
                        "maxFileCount": 1
                    }
                },
                "metadata": {
                    "JTJmZW1haWw=": "/email"
                },
                "recurrence": {
                    "frequency": "Second",
                    "interval": 5
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnection"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob_1": {
                    "connectionId": "/subscriptions/d2ce31d1-d98f-41a0-ba3f-9db5b1e7bf9f/resourceGroups/Alert-RG/providers/Microsoft.Web/connections/azureblob-3",
                    "connectionName": "azureblob-3",
                    "id": "/subscriptions/d2ce31d1-d98f-41a0-ba3f-9db5b1e7bf9f/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
                },
                "office365": {
                    "connectionId": "/subscriptions/d2ce31d1-d98f-41a0-ba3f-9db5b1e7bf9f/resourceGroups/Alert-RG/providers/Microsoft.Web/connections/office365-1",
                    "connectionName": "office365-1",
                    "id": "/subscriptions/d2ce31d1-d98f-41a0-ba3f-9db5b1e7bf9f/providers/Microsoft.Web/locations/eastus/managedApis/office365"
                }
            }
        }
    }
}

Github Repo Link

Quick Deployment

Deploy to Azure