Sending email attachments via integration service/connectors

Hi everyone,
I’m using the Microsoft 365 “Send Email” activity and need to send attachments for which I have the full path as a string.
How do I add them to the activity?

Hi @simone.trenta, hope you’re doing well. I faced the same issue and solved it this way:

Step 1: Store your full file path in a String variable, for example:
filePath = “C:\Reports\Test.xlsx”

Step 2: In the Microsoft 365 → Send Email activity, go to Attachment(s).

Step 3: Click the + button and select Text / Expression.

Step 4: Pass your filePath variable there.

Step 5: If you have multiple files, add each file path separately or create a collection of file paths and use that collection.

This worked for me when the attachment path was already available as a String. Hope it helps!

@simone.trenta

If you have a single attachment, pass the attachment this way. just replace your file path at string.

New List(Of UiPath.Platform.ResourceHandling.IResource) From {UiPath.Platform.ResourceHandling.LocalResource.FromPath("your file path")}

If you have multiple files to attach, just create a list with all the file paths in it and then use below expression to convert list to IResource.

listOfFilePaths.Select(Function(filePath) UiPath.Platform.ResourceHandling.LocalResource.FromPath(filePath)).ToList()

Hi @simone.trenta,

In the below expression, just replace C:\Rpa Files\Temp with your actual attachment folder path:

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

This will pick up both cases, whether there is one attachment or multiple attachments in the folder.

Thanks!

If I need to send multiple files, how can I do that?

Hi @simone.trenta,

You can use the same expression, as it will handle both scenarios. You only need to provide the folder path where the attachments are saved. It will pick all the files available in the folder.

Note: The total size of all attachments should not exceed the maximum attachment size allowed by Outlook.

Thanks!

Hi,
If I had a list of files that weren’t all in the same folder, how could I handle that?

In that case, you can use this approch.

In the Attachments field, use:

vb: LocalResource.FromPath(strFilePath)

For multiple paths in a list:

vb

filePaths.Select(Function(p) CType(LocalResource.FromPath(p), IResource)).ToList()

If LocalResource gives an error, import the namespace UiPath.Platform.ResourceHandling.

Hi @simone.trenta
Since you already have the full file path as a String, convert it to an IResource before passing it to the Attachment(s) property.

For a single attachment:

New List(Of UiPath.Platform.ResourceHandling.IResource) From { UiPath.Platform.ResourceHandling.LocalResource.FromPath(filePath) }

where filePath can be:

“C:\Reports\Test.xlsx”

If you have multiple file paths in a List(Of String), you can use:

listOfFilePaths _ .Select(Function(filePath) UiPath.Platform.ResourceHandling.LocalResource.FromPath(filePath)) _ .ToList()

Then pass the result directly to the Attachment(s) field of the Microsoft 365 Send Email activity.

Also make sure the files exist at those paths and are accessible to the Robot at runtime.