How can I extract the Dynamic hyperlink text from the Gmail body?

Hi
I’m working on email automation to extract emails from a particular sender.There will be dynamically changing hyperlink text in the email body for each email.

using the Get IMAP Message Activity to get emails into for each loop.Later, I used the Find matching pattern activity to obtain the linked text.
Pattern - “<u>(.*?)</u>”
while printing the Find matching pattern activity output i getting the error like
“Log Message: Object reference not set to an instance of an object.”

Thanks in advance and best regards

Try using URL from find matching patterns

Regards,

@chandrakala.productanalys

Hi @chandrakala.productanalys

Have you created the variable in the output of the Find matching pattern activity.

Hope it helps!!

@chandrakala.productanalys

Could you please check whether the data in mail have been retrieved or not ?

Regards

yeah…i have created the variable for it…it was showing error like - Object reference not set to an instance of an object.

Hi @chandrakala.productanalys

  1. Use the Get IMAP Mail Messages activity to retrieve emails and store them in a list of MailMessage objects called mailMessages.
  2. Use a For Each activity to iterate through each email in the mailMessages list.
  3. Inside the For Each loop, use the Find Matching Pattern activity to extract the linked text from the email body using the pattern "<u>(.*?)</u>". Store the output in a variable called matches.
  4. Use an If activity to check if matches is not null and contains any elements.
  5. If matches is not null and contains elements, use a Log Message activity to print the linked text. Otherwise, you can handle the case when no linked text is found.

Regards,

Hi @chandrakala.productanalys

Have you create a variable in Find Matching Patterns activity.
In the properties panel of Find Matching Patterns if you save the output in Result it will stored in the datatype IENumerable(Match) so, in Log message you need to give yourvariable(0).

If you are storing it in First Match you can pass the output variable directly in log message.

Hope it helps!!

There is data…iam using the log message to print the body of the mail

@chandrakala.productanalys

In Pattern property give Regex code
In Text to search in property give input
In First Match create output variable

Okay @chandrakala.productanalys

Could you check the Input variable has data. If there is no data in the Input variable it will throw the Object reference error.

Check with the log message to print the input variable data before the find matching patterns activity.

Try to debug the process and find which activity throws the error is it find matching pattern or get imap mail message activity. Confirm with this.

@chandrakala.productanalys

yes, I agree there is an data but this error basically occurs when there is no input data for the find matching pattern activity. SO could you please try printing the body of the mail first.

Regards

Hi @chandrakala.productanalys

  1. Check if the Find matching pattern activity is correctly configured with the right input (email body) and pattern . Make sure the pattern is valid and will actually match the dynamically changing hyperlink text.
  2. Confirm that the Get IMAP Message activity is correctly retrieving emails with the desired content. You may want to inspect the email contents to ensure they contain the expected pattern for the hyperlink text.
  3. Verify that the output variable of the Find matching pattern activity is correctly assigned and defined. Double-check its scope and initialization within the For Each loop to avoid null reference issues.

Hope it helps!!

@chandrakala.productanalys

Please check input of Find Matching Pattern whether it is correctly given or not

@chandrakala.productanalys

If you are using the invoke workflow activity then please check whether you have passed the variables and arguments correctly.

Regards

i have given the input for finding matching pattern was output of the Get imap activity

@chandrakala.productanalys

you should use the for each for the output of the get imap activity and within that use the item as variable and that item.body must be given as the input of the find match pattern activity and the find match pattern activity should be placed within the for each.

Hope it helps!!

Hello @chandrakala.productanalys

You are either:
Have no matches (emails) to extract from your input email
OR
Your regex pattern is not working.

Why not try using this pattern:
[^\s]+@[^\s]+

Cheers

Steve

showing same error like-Log Message: Object reference not set to an instance of an object.

Hi @chandrakala.productanalys - Before trying in the UiPath can you please try your expression in the below regex website. This would help you to know the pattern you are using is right or no.