Email Attachment from folder

Hi guys,

i have one folder path is C:\Rpa Files\Temp.
i need to send outlook email with attachements all the file from above folder if possible pls send me a workflow screenshot its help full for me.

Hi @MD_Farhan1 ,
You can try these steps:

  1. Use Assign activity:
    filesArray = Directory.GetFiles(“C:\Rpa Files\Temp”)

  2. In the Send Outlook 365 Email activity, set Attachment(s) to:
    filesArray

Or directly:
Directory.GetFiles(“C:\Rpa Files\Temp”)

Workflow (Simple):

Assign
    filesArray = Directory.GetFiles("C:\Rpa Files\Temp")

Send Outlook 365 Email
    To          = "user@company.com"
    Subject     = "Files from Temp Folder"
    Body        = "Please find attached files."
    Attachment(s)= filesArray

Alternative: If you need to filter specific files (for example only PDFs):

Directory.GetFiles(“C:\Rpa Files\Temp”,“*.pdf”)

Thanks

what datatype of filesArray?

You can use String filesArray.

i got error

  1. Create variable filesArray

    • Type: String[]
    • Value:
      System.IO.Directory.GetFiles(“C:\Rpa Files\Temp”)
  2. Pass filesArray into Send Outlook 365 Email → Attachment(s).


i got error in send email attachments

The error is because the Microsoft Outlook 365 Send Email activity expects IEnumerable<IResource>, not a String[] of file paths.

Use Create File Resource activity inside a For Each loop:

fileArray = System.IO.Directory.GetFiles(“C:\Rpa Files\Temp”)

Workflow:

  1. Assign:

    fileArray = System.IO.Directory.GetFiles(“C:\Rpa Files\Temp”)

  2. Create variable:

    attachmentsList
    Type: List(Of UiPath.MicrosoftOffice365.Models.IMailResource)

  3. For Each file in fileArray

    • Use Create File Resource
    • File Path = file
    • Output = fileResource
    • Add fileResource to attachmentsList
  4. In Send Outlook 365 Email → Attachment(s):
    attachmentsList

Hi @MD_Farhan1,

Check this:

Thanks!

Hi,
This is changing file format but i need all file from folder to email attachments.

still got error better make a workflow then screenshot easy to understand

Hi @MD_Farhan1,

Use the below expression:

System.IO.Directory.GetFiles(“C:\Rpa Files\Temp”).Select(Function(f) LocalResource.FromPath(f)) .ToArray()

If this solves your issue, please mark the answer as the solution.

Thanks!

@MD_Farhan1

Please follow the below steps,

take assign activity, create a variable (arrFiles) variable Type = Array of string(String)
In Send Email Activity, open attachment section and pass the below expression,

arrFiles.Select(Function(path) LocalResource.FromPath(path)).ToList()

This is i tested and it worked.

Let me know if this works for you as well
If works please mark it as solution.

Happy Automation

Welcome to the community

There are two ways

  1. Use expression - {LocalResource.FromPath("C:\Users\A\Downloads\file.format")}
  2. Click on plus near attachment and then select the file as it gives the ui option to select