How to get a dynamic Links in Mail Body content?

@keerthi_arumugam , Could you Let us know How are you Reading the Emails ?

Are you using UI Automation or using Mail Activities such as Get Outlook Mail Messages ?

Mail Activities…

@keerthi_arumugam , In that case, Could You provide us with the Data from the mailMessage variable ?

mailMessage.Body should provide you with the contents of the mail Body. If this doesn’t contain the data, then using mailMessage.Headers("HTMLBody") should provide us with the full content of the Mail.

We can then use Regex to extract the links from this text data.

1 Like

in addition to @supermanPunch

when receiving the HTML Body alternate: YourMailVar.BodyAsHtml()
we can react on the a elements an on its href attribute w.g. with regex


refering to group:
grafik

simplified to only href anchoring:

In case we want to avoid to grab every present link and scope to the Download text we can do:


grafik
(?<=href=")(.*?)(?=")(?:.*?)(?=Download)

Can you please give me as a xmal file please…

will not help you much, as we don’t have the download links contents

But in general it is about:

  • get mail
  • iterate over the mails with a for each
  • retrieve within an assign the email body: strBody = yourLoopedMailVar.BodyAsHtml()
  • use regex eg
    arrLinks = System.Text.Regularexpressions.Matches(strBody, YourPatternVar).Cast(of Match).Select(Function (m) m.Groups(1).Value).toArray

YourPatternVar = (?<=href=")(.*?)(?=")(?:.*?)(?=Download)

More about regex you can find here:
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

1 Like

Yes, will started trying already…so if any queries, let you know…

Hello @keerthi_arumugam,

One question - Do we get the dynamic links in the email body starting with “https*” ?

If Yes then

We can use the “Split” operation on “ExtractedEmailBody” with the word “https://” and do the rest of the string manipulation functions.

Please refer to the attached file for a basic solution to extract dynamic links from the email body.
Outlook_ExtractingDynamicLinks.xaml (11.5 KB)

1 Like

No,But i have the specific word like “Capital Account Statement” prefix the Download(link) in boday content

1 Like

Hello @keerthi_arumugam,

I suggest you to use the workflow file attached to the above reply to test emails at your end. I have designed and tested it in such a way that it will extract any dynamic link in the email body.

Assumptions -

  1. Only 1 link will be there in the email body
  2. Link should be starting with https://
    Eg. -

PFA - Sample Email body I used for testing the above workflow file. It is capable of extracting links irrespective of email body content as far assumptions mentioned above are met.
Note - If it does not meet your requirement then do share a sample email body or similar content so that it will clear my doubts.

1 Like

Hi,I need to get a link by the specific word.

For example:
if a mail body content is displaying the “Download” or some other word is displayed and need to get the inner link of the word.

body HTML.txt (25.1 KB)
I need to Extract the Link by Prefix with Capital Account Statement and also download link

Hi @keerthi_arumugam ,

So, In this Case, Do you want to extract the links from the First 3 rows as the 3 rows are Having Capital Account Statements and Download ?

1 Like

yes I think

do you have any solution for that?

Hi @keerthi_arumugam ,

Could You try to use the Regex Expression below :

(?<=Capital Account Statements)(\n*\s)*</td>(\n*\s)*<td.*\n*<a\s*href=\""(.*?)(?=\"")

You Could follow the below Steps :

  1. Use Matches Activity, Pass the Pattern as mentioned above. Input would be your Email Body String.

  2. Create an Output variable, say matchings.

  3. Next, we can use this Output to get the links list and convert it to an Array of String.
    Using an Assign Activity we can do the following :

linksArray = matchings.Cast(Of Match).Select(Function(x)x.Groups(3).ToString).ToArray

where linksArray is a variable of Type String Array

Visual of the Extraction in Debug :
image

Let us know if the steps doesn’t work or if you face any difficulties.

1 Like

Matching(0) is the o/p solution for 1st link right?
Group(3) what it means?

@keerthi_arumugam ,

Yes.

According to the Input Data, and the Output Expected for the Pattern to match, we have 3 Matches.

The Matched outputs are stored in matchings variable, which we can access using indices 0, 1, 2…

It is How we have compose the Pattern, the Data needed to be Extracted is closed within the 3rd Group

To access the Groups we use .Groups on the Matches activity output. Here again we access the Group Number required.

However, Do we have the Expected Output as you Required?

I suggested the Array of String Output approach, so that we’ll have all the links required as an Array.

Is this been Checked?

1 Like

Hey , did you get the solution for this ? I have same query and not able to get it.