Save Attachments About the files extensions

************* Save Attachments *************

At a time, it downloads all the attachment together from the current single email message.

  • By Default, all the attachments are downloaded in the Project Folder.
  • Add Specific DownloadFolderPath to download the email attachments.

Download the files from email

  • Get Outlook Mail Messages Activity that returns ListMailMessages.
  • For each messageItem in ListMailMessages.
  • Place the Save attachments Activity.
  • Message = messageItem
  • FolderName = DownloadFolderPath
  • Attachments will be saved.
  • Next Iteration
  • End of For Each

Extract Attachment Information

1. Download various or single type of attachments.

  • Place Save Attachments Activity.
  • Update the Filter
  • Filter = (.xlsx|.pdf|.docx|.xls)

2. Download only if specific type of attachments is available

  • For each messageItem in ListMailMessages.
  • If-> messageItem.Attachments.Any
  • True then,
  • If → messageItem.Attachments.Where(Function(x) x.Name.Contains(".xlsx")).Count >0
  • True then,
  • Place the Save attachments Activity.
  • Message = messageItem
  • FolderName = DownloadFolderPath
  • Here, it will download the .xlsx attachment and also other attachments if any available.
  • End For

3. The Save Attachments has a output variable known as Attachments.

  • Returns a List of Attachments for a given email.
  • Type : System.Collections.Generic.IEnumerable<System.String>
  • For each AttachItem in ListOfCurrentEmailAttachments
  • Set the ArgumentType = System.Net.Mail.Attachments
  • Assign strExtension = Path.GetExtension(AttachItem.Name).ToString
  • Now strExtension will contain “.xls” value.
    Depending upon the attachment extension

4. Download the attachments with same names.

  • If OverwriteExisting is selected, the existing file will be overwritten.

5. Create a DownloadFolderPath based on Email SubjectName or TodaysDate

  • You can create folder and name it as per the SubjectName. However, precheck if there any symbol in SubjectName
  • SubjectName = messageItem.Subject
  • TodaysDate = Now.ToString(“dd_MM_yyyy”)
  • Assign DownloadFolderPath = “C:\Users\Geet\UiPath\EmailAttachment\TodaysDate\SubjectName\”
  • Check DownloadFolderPath Path Exists
  • If not then Create Folder
  • Download.

Feel free to let me know more about the UiPath Activity Save Attachments
Also, Please correct me, if you find something needs to be changed or corrected.

Regards,
Geet M

4 Likes