Attach files from dynamic folders to "Send Outlook Mail"

Hi,

Im having some problem attaching .xlsx files from a folder to “Send Outlook Mail” activity.
There are 5 .xlsx files that i want to attach, but i cant get it working?

I also want to do the same but with a dynamic number of files?

Hope someone can help me with how this can de done.

Are you getting any error message? I hope you are using attachfiles property and passing file variable into path column in send outlook email activity.

To pass dynamic files , you can create a mailmessage object and attach files to it and pass that object in your send outlook email activity.

Someone provided sample in the past, please search the forum.

Hey @SoJo

Hope This link might give you an idea :slight_smile:
How to insert attachment in UI path SMTP activity - #2 by aksh1yadav

Regards…!!
Aksh

4 Likes

hi aksh1yadav i m unable to open your project on my ui path.
The issue i am facing is i can attach one or more files when i use the hardcoded path but how can i make it send all the files that exist in an a folder
?

What version of UiPath Studio you are using?
Well mine was 2016.2.6274.

You can Get all files from Directory by using System.IO.Directory.GetFiles("Attachments") or Directory.GetFiles("Attachments")(If System.IO Namespace is already imported).

Basic Flow:

1. String[ ] fileNames_to_be_attache= Directory.GetFiles("Attachments")
2. System.Net.Mail.Message mail = new MailMessage()
3. For Each with type argument String.

foreach item in fileNames_to_be_attache{
System.Net.Mail.Attachement attachment = new Attachment(item,System.Net.Mime.MediaTypeNames.Application.Octet)
Invoke method -activity
type - (null)
TargetObject - mail.Attachments
MethodName - Add
}
parameter for invoke method-

Rest steps you can find in the image:

Regards…!!
Aksh

Hi Akash
i have downloaded ur solution its showing it has files in folder but while sending mail its not attaching the files.

check your local path and folder which you are giving it.

Hi

i have replaced Send SMTP mail to Send Outlook mail so property Forward - > MailMessage → mail was pending to be added now its working.

thanks Akash

Use of below statement in ur code
new Attachment(item,System.Net.Mime.MediaTypeNames.Application.Octet)

Got Directory not found exception while executing above Xaml file.

Cross check Your directory … name :slight_smile:

Even i am trying with send outlook,what we should change in code?Can you post your sample code here

Hi @aksh1yadav I am using your attach and send mail for outlook and i am able to snd mail but attachments are not getting attached to mail and i have bverified the path in write line it is showing the two file names properly ?

Hey Akash,

I used ur project u had shared earlier, i worked.
But is it possible to take the latest file that arrived in that particular directory and attach the same into the mail.