The article presents an easy and fast way on how to build an email automation that downloads all attachments into a specific folder. Of course, this example can be extended to an even more complex degree. To give you an idea you can filter the emails or download only files with a specific extension. But this is all up to you. Be creative. I’ll give you some hints along the way.
We will start with a new automation process. Let’s call it Email Automation.
Add a new Flowchart and inside drag and drop a new Sequence. Rename the Sequence to Download Email Attachment.
Open the sequence and create 3 new variables:
- EmailAddress – String type
- EmailPassword – String type
- MailMessages – List<MailMessage> type (System.Net.Mail.MailMessage)
Drag and drop a new Assign activity and set the EmailAddress to your email address.
Drag and drop a new Get Password activity and set the EmailPassword variable. On Misc section set the Password and on Result select EmailPassword variabe.
Next, drag and drop Get IMAP Mail Message. Make the following changes:
- Set MailFolder to “Inbox”
- Port to 993
- Server to “imap.gmail.com”
- Email to EmailAddress variable
- Password to EmailPassword variable
- Top to 10 (get the first 10 emails)
- Save the Messages to MailMessages variable
Drag and drop a new For Each activity and inside of it drop an If activity. It should look like this:
Inside Then branch drag and drop the Save Attachment activity. Set the Message as item variable and select the path where to download the email attachment.
If you want to download only specific files use the Filter option on Save Attachment activity. For example, if you want to download only .jpg and .png files use this regular expression as a filter:
Before running the email automation please configure your Gmail account for IMAP/POP3 protocols and generate and use an App password from Google. For more details follow this link (source: UiPath)
Download the solution
Click on the button below to download the source of the demo (Download Email Attachment).