3 min to read
Automate Email with Azure Logic App
Automation with playbook
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
- Storage account creation
- Logic App
Requirements :-
- Azure Subscription
- Storage Account access
- Logic App contributor access
- Email group either outlook or gmail
Steps :-
- Signin to Azure Portal and search storage account and click on create and fill deatails for storage account.
-
In Redundancy select LRS i.e locally-redundant storage to reduce cost. By default it comes with Geo Redundant storage
-
Under Advance section change blob storage access tier type from Hot to cool unless you are using it for enterprise and you need to store all data for GDPR compliance. And Enable large file share option too . But large file storage option do not have the ability to convert to geo-redundant storage offerings and upgrade is permanent.
- Under networking section enable network for selected VM and IP address for security and avoid unwanted traffic . We can use Private network access too.
- Under Data Protection Tab, enable all features as per your GDPR compliance and requirements.
-
To reduce cost make sure to tick delete icon and set no of days.
-
If one want to encrypt the storage account feel free to use encryption tab.
-
Review and hit create
Storage and Container creation
- From left tab select Data storage drop down and click container
- Click on create and put unique name, from public access level dropdown select Blob storage
- After successful creation , container will look like this
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
- While Creating logic app make sure to select consumption based to reduce cost
- Click on blank logic app
- Select trigger as Blob is added or modified properties only v2
- Fill Azure Blob storage
- Select how often blob storage should scan
- Fetch Blob storage
- Send Email connect
- After successful run it’ll trigger
- Recipient Mail snapshot
- Senders Mail snapshot
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 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"
}
}
}
}
}
Comments