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

7 Likes

Do you know how to save attachments from forward messages ? Because they are written to me as @ 0KB

My attachment from Outlook is XXX.zip folder.

  1. I want it to save as YYY.zip then extract the file from the saved folder, then rename the extracted file

OR

  1. save the file as is, then extract, then rename

My hiccup currently is I put the variable ‘Output’ of my ‘Save email attachments’ activity as YYY since the saved file later can be any name.
Next, I use ‘Extract/unzip file’ activity to unzip YYY. In ‘File to extract’ section, I want to put YYY.Fullname.tostring, but it throws me an error.

How can I recall the path of YYY.