Require to retrieve a link from an email

From the below attached email, I want to retrieve the link which redirects to the csv file.

So, I have retrieved the mail messages, put it into a loop , retrieve the download link as a string, then open a browser and navigate to that that link for further download.

Could you please let me know how to modify the expression for downloadable link.

strDownloadableLink = System.Text.RegularExpressions.Regex.Match(item.Body.ToString, “https://[^\s]+”).Value

@Yoichi @postwick could one of you please help me here.


Check this:

Hope it works.

Hi @supriya117 ,

This did not work for me

Have you tested with item.HTMLBody instead of item.Body?


Try this:

System.Text.RegularExpressions.Regex.Match(currentItem.BodyAsHtml.ToString, “https://[^\s]+”).Value

Hope it will helps you :slight_smile:

Hi @Nawazish_Ahmad ,

This redirects to the below page.

But the expected page must be as below.

Can you share the download link. It’ll be easy to extract the link from it for downloading file.


You can use Extract Text Activity to get First or All URLs from mail. Change “What to extract” to “URLs” and pass mail.BodyAsHtml as input


1 Like

Hi @Nawazish_Ahmad ,

The download link keeps changing based on the date.


To retrieve a specific link from an email that directs to a CSV file, as mentioned in your description, and considering the structure of the email shown in the first image, the Regex pattern needs to specifically target the URL structure that’s typically used for such links. Given that you’ve already set up the logic to loop through emails and identify the link, you just need to refine the Regex pattern.

The pattern you provided ("https://[^\s]+") will match any URL that starts with “https://” and continues until it hits a whitespace. This is a good start, but if there are multiple links in the email body, it will only capture the first one. To ensure you’re capturing the correct CSV file link, you can modify the Regex pattern to be more specific. If the link has a predictable structure, such as always containing the word “download” before the “.csv” part, you can include this in the Regex.

For example, if the link to the CSV file is always in the format https://.../download/.../file.csv, the Regex pattern can be:

strDownloadableLink = System.Text.RegularExpressions.Regex.Match(item.Body.ToString, @“https://[^\s]+/download/[^\s]+.csv”).Value;

This pattern looks for a string that starts with “https://” followed by any characters that are not whitespace, includes “/download/”, and ends with “.csv”. Remember to escape the dot before “csv” since a dot has a special meaning in Regex and you want to match it literally.

Make sure to test the pattern with actual email content to ensure it’s matching correctly. If the structure of the CSV file link varies, you may need a more complex or different pattern.

After setting the strDownloadableLink with the correct Regex pattern, the rest of your process that navigates to the link should work as expected.

Hi @srinivasmarneni ,

One of the sample url would be like below

this link extends and differs based on date

But in the email, it is always Download .csv file.
I have been struggling with this from last day. Could you please help to sort it out.

Step 1: Retrieve Emails

  • Use the “Get Outlook Mail Messages” or another relevant activity to fetch emails into a variable, let’s call it mailMessages.

Step 2: Loop Through Emails

  • Place a “For Each” activity to loop through mailMessages.
  • Inside the loop, use an “If” activity to check if the body of the email contains the text “Download .csv file”. The condition will be item.Body.Contains("Download .csv file").

Step 3: Extract the Download Link

  • In the “Then” section of the “If” activity, use an “Assign” activity to extract the link.
  • Create a variable named strDownloadableLink.
  • Use the following Regex pattern in the Assign activity:

System.Text.RegularExpressions.Regex.Match(item.Body.ToString, “href=”“(https?://\S+?.csv)”“”).Groups(1).Value

This pattern matches the href attribute of an anchor tag that points to a .csv file. The \S+? part matches any series of characters that are not whitespace, stopping as soon as it reaches “.csv”.

Step 4: Navigate to the Download Link

  • Still inside the “Then” section and after the Assign activity, use an “Open Browser” or “Navigate To” activity (if you already have a browser session open) to navigate to strDownloadableLink.
  • You might want to use an “If” activity to check if strDownloadableLink is not empty before trying to navigate.

Step 5: Download the File

  • After navigating to the URL, use whichever method is appropriate for the website to initiate the file download. This might involve clicking a “Download” button or waiting for the file to start downloading automatically.

Step 6: Error Handling

  • In the “Else” section of the first “If” activity, or in the “Catch” section of a “Try Catch” activity, handle the scenario where the link is not found. You can log a message saying the email with the download link was not found.

sample code:
Get Mail Messages → Output to ‘mailMessages’

For Each ‘item’ in ‘mailMessages’
If item.Body.Contains(“Download .csv file”)
Assign ‘strDownloadableLink’ with Regex to extract the URL
If ‘strDownloadableLink’ is not empty
Navigate to ‘strDownloadableLink’
Download the file
Log message “Download link not found.”
Log message “Email does not contain the expected text.”

  1. Make sure that your Regex pattern is correct and test it with actual data. Adjust the pattern if necessary to match the exact structure of the links in your emails. This workflow should be able to automate the process of retrieving the .csv file download link from your emails.

Hi @srinivasmarneni and @rikulsilva ,

I will check both and get back to you.


Complementing the usage of Extract Text activity… after you get all URLs, you can extract the desire one like this (in case there is more than one url in the mail body)

downloadedURL = allURLs.Where(Function (x) x.Contains("csv-exports/org-members/")).First()

Hi @srinivasmarneni ,

as per the step 2, my url does not end with .csv, instead with random ids as below


After extracted desired URL you can use Download File from URL Activity without need change anything



Use Same Flow with the below Regex Pattern.


Hi @Nawazish_Ahmad ,


This is throwing the below error.

Hi @srinivasmarneni ,

Based on the condition If it went to Else condition of the If saying email with download link do not exist.

try this…

System.Text.RegularExpressions.Regex.Match(inputString, “pattern”).Value

f your pattern includes backslashes (such as for escaping or denoting special regex characters), you would need to double them in VB.NET:

System.Text.RegularExpressions.Regex.Match(inputString, “https:\/\/example\.com”).Value