Skip to content

Sending Emails from Azure Logic Apps & Service Bus

Pre-requisites to follow along this tutorial

  • Azure Account 
  • Email Provider (such as Post-mark, SendGrid…)

 

Sending Emails through Azure Logic Apps become easier in most of the business requirements, specially triggered by Azure service bus, to learn more about Azure service bus please use the following link https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview

now let’s back to the point.
 
Azure Service bus messages can be queued based on topics and subscriptions, it will be categorized as following hierarchy
  • Service bus namespace
    • Topic
      • Subscriptions
Steps to Follow
Create a Resource Group and Create a Logic App
Create a new workflow
 
in Designer View Your Trigger Should be as follows
When messages are available in a topic subscription 
 
 
Provide Your connection string of Service Bus with Topic and Subscription Name
 
Sample ARM template for your Logic App as follows
{
    "inputs": {
        "parameters": {
            "topicName": "your-topic-name-here",
            "subscriptionName": "your-subscription-name-here"
        },
        "serviceProviderConfiguration": {
            "connectionName": "serviceBus",
            "operationId": "receiveTopicMessages",
            "serviceProviderId": "/serviceProviders/serviceBus"
        }
    },
    "splitOn": "@triggerOutputs()?['body']"
}
 
 
  • Create an HTTP Action
  • Method: POST
  • URI: Your Email Providers Post API endpoint URI
 
Headers: Probably Your Authentication Token and Other Header Details Comes under header section
Body: You can extract your Message from Service in Body Section I will provide a sample ARM template below
 { 
    "inputs": { 
        "method": "POST", 
        "uri": "your-email-service-provider-API-endpoint", 
        "headers": { 
            "token": "your-authentication-token", 
            "content-type": "application/json" 
        }, 
        "body": { 
            "From": "@triggerOutputs()?['body']?['UserProperties/from']", 
            "HtmlBody": "@triggerOutputs()?['body']?['UserProperties/htmlBody']", 
            "ReplyTo": "@triggerOutputs()?['body']?['replyTo']", 
            "Subject": "@triggerOutputs()?['body']?['UserProperties/subject']", 
            "To": "@triggerOutputs()?['body']?['to']" 
        } 
    } 
}
 
that’s it, save the workflow, and your workflow will be triggered every time your Service received a message on specific subscription which you provided while you are creating the trigger.