Send mail with variable file number without giving error


I have a process that sends email with two files (one always exists), but sometimes the second file does not exist, since it is not necessary to send it, it can be done that if the second file does not exist, no error and send the mail via SMTP with a single file? or do I have to do it with IF?

A greeting.

You can use LINQ to get a list of only files that exist and then provide that list to the SMTP activity.

fileList = {"C:\Test\File1.txt", "C:\Test\File2.txt"}.Where(Function(f) File.Exists(f)).ToList


But I do not know the name of the files and the quantity, since they will vary every day.

Do you know where the files are located?

Hi @Aguirre

Instead of File name try to use *



YES, the file folder is always the same

Then you can just use Directory.GetFiles() to get the files:

To get all the files in a folder:

To get only pdf-files in the folder:
Directory.GetFiles("C:\Test\FilesToSend", "*.pdf")

Hello, I have doubts about this and perhaps I have not explained myself well, I have a directory of invoices and another directory of attached files, the mail always has the invoice, but not always the attachment, I give an example:

Invoice100.pdf + 100.pdf
Invoice101.pdf + //Without PDF
Invoice102.pdf + //Without PDF
Invoice103.pdf + 103.pdf

Finally, I have used the simplest solution and it works. I’ve added the “file exists” activity, and the IF sends me back with one or two files. As I always know that it will be one or two I have no problem, if there were more files I would have to find another solution.
Thanks. @ptrobot & @Gokul001


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.