Data extraction from Gmail and PDF's download

Hi every. I’m still new to UiPath so every help is welcome :slight_smile:

The process is about downloading the secured PDFs in gmail and writing the data of those PDFs in excel. I succeeded in the extraction part from PDF to excel, just not the gmail part.

It’s like this: Every PDF is protected and the password is in the mail. It is namely the last 4 digits of the date (datum) and order number (bestellingnummer). So 2019 of date 26-2-2019 and 6534 of Ordernumber 166534, the password is 20196534. So I need to get the password’s and download the PDF’s from every mail. Any idea how I can tackle this?

1 Like

Hey @s.altindag

The date and order number will come from email ?



  • To parse the content from the body and form the password, you can use regex and then
  • Substring methods to get the last four digits and concatenate it to a variable
    Manage Package>UiPath.Mail.Activities
  • Then You can use “Save Attachments” activity where you need to pass two arguments:
  • Your mail message and path where You want to save file stored in some variable.

Best wishes,

You can try regular expression for extracting that from Gmail.

For extracting date you can try this code : (?<=Datum:)(\s)+(\d+[-./]\d+[-./]\d+)

For bestellingnummer : (?<=bestellingnummer:)\d+

year from date try this in assign activity : “Yourdatestring”.Substring(“Yourdatestring”.Length-4)

if you want more characters instead of 4 you can increase or decrease number


Yes, both numbers will come from the e-mail


So what is step procedure in this one? I guess i start with the activity IMAP Mail message and then what?

Kind regards,

Hi @s.altindag,

You can use IMAP or you can use the Gmail activities if you have gmail installed.
But yes, you’ll want to:

  1. Authenticate with email server
  2. Get specific Mail
  3. For Each Mail
    a. Save Attachment
    b. Get Mail Body as string
    c. Extract content from body to create password
    d. Write to Excel

Hi thank for the reply,

I’m using the IMAP get mail activity, but the only problem that i’m facing now is that my item.body is returning empty cells. The item.subject works fine, but not the other one. I looked up for solutions, but item.Headers(“PlainText”) and item.Headers(“HTMLBody”) aren’t working :frowning:


1 Like

Hello @s.altindag,

You can get the email body text by mailmessage.body property and for deleting you can use Move IMAP mail message to a different folder.

And the reason for getting a blank mail body may be because it’s in html format, other than plain text. If so, read the html mail body by mail.Headers(“HTMLBody”) and convert it to plain text using the regular expression, System.Text.RegularExpressions.Regex.Replace(mail.Headers(“HTMLBody”),"(<.?>)|({.})","") or you can use the key mail.Headers(“PlainText”).

Best Wishes

But still your mail has body text ?


Hi, Thanks for the reply. I have found my solution. I needed to use instead of () en i don’t know why :l


1 Like

Hey @s.altindag

You may have created your project with C# language compatible instead of VB.NET


Hi, thank you for the information!

take care

1 Like

Try this :

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.