Extract URL link behind email body using LogicApps

Sergio Antonelli 0 Reputation points
2023-08-22T12:29:43.86+00:00

Hi guys,

I'm trying to retrieve a .csv file from a recurring email I receive every day. This .csv is stored within a hyperlink, as seen below:Capture

I've seen one solution using azure functions to retrieve the link, and then submit an http request to get the file downloaded and saved into a blob container, but this didn't really go into much depth in terms of the azure function creation. I have a pretty good idea of what to do once I have the link, but not too sure how to retrieve it. Any ideas?

Thanks in advance!

Sergio

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,702 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,457 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,418 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,896 Reputation points
    2023-08-22T13:10:58.1033333+00:00

    @Sergio Antonelli Thanks for reaching out. There is no out of box feature to get the csv link and you need to use the regex expression to extract the link from the body of your email. You can either use logic app inline code (that needs Integration account) to perform this operation or offload this function to Azure function. For your reference I am share the email body of my trigger and based on my body I have used the regex to extract the link

    Email Body Content:

    "<html><head>\r\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style>\r\n<!--\r\n@font-face\r\n\t{font-family:"Cambria Math"}\r\n@font-face\r\n\t{font-family:Aptos}\r\np.MsoNormal, li.MsoNormal, div.MsoNormal\r\n\t{margin:0cm;\r\n\tfont-size:11.0pt;\r\n\tfont-family:"Aptos",sans-serif}\r\na:link, span.MsoHyperlink\r\n\t{color:#467886;\r\n\ttext-decoration:underline}\r\nspan.EmailStyle17\r\n\t{font-family:"Aptos",sans-serif;\r\n\tcolor:windowtext}\r\n.MsoChpDefault\r\n\t{font-size:11.0pt;\r\n\tfont-family:"Aptos",sans-serif}\r\n@page WordSection1\r\n\t{margin:72.0pt 72.0pt 72.0pt 72.0pt}\r\ndiv.WordSection1\r\n\t{}\r\n-->\r\n</style></head><body lang="EN-IN" link="#467886" vlink="#96607D" style="word-wrap:break-word"><div class="WordSection1"><p class="MsoNormal">This is the test link</p><p class="MsoNormal"> </p><p class="MsoNormal">This is the test <a href="***" originalsrc="https://testsite/Free_Test_Data_200KB_CSV-1.csv" shash="*">link</a></p></div></body></html>"

    User's image

    JavaScript Code:

    var text = workflowContext.trigger.outputs.body.body;
    let match=text.match(/originalsrc="([^"]*)"/)
    if (match) {
      return match[1];
    } else {
      return String.Empty
    }
    
    

    Note: The above regex is only for reference and may need to change as per your body content of email by the trigger. If you have more than one link then you need to match the csv format as well. Please modify and test the regex at your end.

    For your reference sharing the you can refer to the inline document. Once you have the link you can use the HTTP action to call any HTTP/HTTPS native URL.

    Feel free to get back to me if you need any assistance.

    Please "Accept Answer" if the answer is helpful so that it can help others in the community.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.