Avoid Repeat Email Attachments Download

Hi,
How to avoid the repeat email attachments download.

Hi @Gowthaman_Subramanian

Create a List of String variable. When downloading attachments from an email, store the downloaded file names in this List variable. Inside the For Each activity, insert an If condition to check if the attachment name is already in the List variable. If it is, do not download the attachment.

Hope it helps!!

@Gowthaman_Subramanian

downloadedAttachments=New HashSet(Of String)()
Not downloadedAttachments.Contains(currentAttachment.Name)
downloadedAttachments=downloadedAttachments.Concat({currentAttachment.Name}).ToHashSet()

I hope this will Helpful to you

Hi bro,
It not working, downloading thrice every running.

Please use following VB Code to download email attachments in a fast manner.
'--------------------------------Copy from here-------------------------------------------
Dim olApp, olNamespace, olFolder, olItems, olMail, olAttachment
Dim savePath, fileName

’ Create Outlook application object
Set olApp = CreateObject(“Outlook.Application”)

’ Get Namespace (MAPI) object
Set olNamespace = olApp.GetNamespace(“MAPI”)

’ Get specific folder by name
Set olFolder = olNamespace.Folders(“emailID@YourCompany.com”).Folders(“AnyFolderNameUnderInbox”)

’ Get the current user name
Set WshShell = CreateObject(“WScript.Shell”)
userName = WshShell.ExpandEnvironmentStrings(“%USERNAME%”)

’ Define the path where you want to save attachments
savePath = “C:\Users"& userName &”\Documents\UiPath\ProjectFolder\input"

’ Loop through all items in the folder
Set olItems = olFolder.Items
olItems.SetColumns(“UnRead”)
Set olItems = olItems.Restrict(“[UnRead] = True”)

For Each olMail In olItems
’ Check if the item is a mail item
If TypeName(olMail) = “MailItem” Then
’ Loop through attachments
For Each olAttachment In olMail.Attachments
’ Check if the attachment is a PDF
If LCase(Right(olAttachment.FileName, 4)) = “.pdf” Then
’ Define the full file path
fileName = savePath & olAttachment.FileName
’ Save the attachment
olAttachment.SaveAsFile fileName
End If
Next
’ Mark the email as read
olMail.UnRead = False
olMail.Save
End If
Next

’ Clean up
Set olAttachment = Nothing
Set olMail = Nothing
Set olItems = Nothing
Set olFolder = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
MsgBox “Email Download Process Completed”

'----------------Copy till here only---------------------------------
This does not depend on any download activity. Copy above code in a notepad and save as “Download.vbs” file and double click on the same file. You can find all unread email PDF attachments will get download in your specified path.

Use Start Process activity to call this VBS file.

Hope you like it.

Hi Rajyalakshmi,

Every attachment iterating from the ‘currentMailMessages’, if the condition is ture, it save all the attachments of ‘currentMailMessages’. How can we download ‘currentAttachement’ only.

@Gowthaman_Subramanian

In the save attachment Give currentAttachment