Save all attachments with new file names

I have attached my .xaml file where I am getting emails with attachments and checking to see if the attachment contains special characters. If the attachment contain special characters, I want to rename the attachment and send the new attachment to an email address. I do not know how to rename the attachment. The new name should be “newname” + today’s date + extension name of original attachment"

1Getemails.xaml (9.2 KB)

Renaming can be done with the move activity file. Simply change the Destination property to be the full file path you want.

So steps to take would be:

  1. save all attachments to folder such as C:\Temp\MailAttachments (have to save them in order to rename them)
  2. In a for each loop (of type string): For each file in Directory.GetFiles(“C:\temp\mailattachments”)
    a. Use a move file activity: From path = file // To Destination = Path.GetDirectoryName(file) + "" + “newname” + today.ToString(“MM-dd-yyyy”) + Path.GetExtension(file)
  3. Add all files in the directory (C:\temp\mailattachments in this example) as an attachment to your mailmessage
  4. Run the garbage collector to dispose of the mailattachment after the email is sent
  5. Delete the files in your directory after the email is sent
2 Likes

Thank you. I appear to be having a problem with choosing the correct object type in the for each loop, i.e. I am getting this error in the destination path of the new file:

image

In the for each activity, change the TypeArgument property from Object to be ‘String’ instead
for%20each%20type%20change

Thanks Dave. That did it. Really appreciate the help.

Do you mind to share your workflow ? I’m working with a process where I also need to rename the files

Hi Annie,

see attached. it is very simple.Rename Files.xaml (5.3 KB)