Reputation: 504
I'm a beginner with Azure and want to be able to have a Logic App to read the contents of an email and output it in JSON such as:
{
"from": "[email protected]",
"subject": "Azure Exception - A task was canceled.",
"body": "An exception has occurred in an Azure function"
}
The logic app is very basic, I have a 'when an email is received trigger' leading then to my Function App in which i am passing the Email Body as the request body. I am currently getting the http body request stuff back from the logic app such as:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style>
<!--
@font-face
{font-family:"Cambria Math"}
@font-face
{font-family:Calibri}
This is not what I want as the main bit of the email that I want is at the bottom as html.
In my function app I am doing the following, taking the req and
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string emailBodyContent = await new StreamReader(req.Body).ReadToEndAsync();
return new OkObjectResult(emailBodyContent);
}
I'm not really sure how this works but I'm returning the req.Body
.
I am assuming that it might be something to do with the below? As we could do from: Email From, Subject: header
Any guidelines or answers is much appreciated.
Upvotes: 0
Views: 2544
Reputation: 4164
My understanding that you would like to extract the mail body (plain text) rather than having the complete html text.
By default, in the logic app - the email body received is HTML content. To Extract the text content you can use the Content Conversion connector.
Alternative :
You could use the Body Preview
- if the body is smaller - the body preview will have the plain text of the body - which will directly meet your requirement.
To create JSON output you could make use of the Compose Action
Upvotes: 5