What @Nived_Nambiar suggested there is pretty much the essence of it. There are two things to note though:
- You might want to handle all attachments, and not only the first one. An email can have more than one. Even the images in an email signature are considered to be an attachment. So, inside the loop for email messages, you might also want to have an extra loop for attachments for each message.
- You might want to sanitize the subject text to remove any special characters that are not valid in Windows system file names.
To handle point no. 2, use Replace text with regular expressions to replace the following characters:
- < (less than)
- > (greater than)
- : (colon)
- " (double quote)
- / (forward slash)
- \ (backslash)
- | (vertical bar or pipe)
- ? (question mark)
- * (asterisk)
You can do it via a single Replace text action to replace it all with a whitespace or an underscore or something. You can copy the following code to your PAD designer to have the action inserted automatically:
Text.Replace Text: Email.Subject TextToFind: $'''[<>:\"/\\\\|?\\*]''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''%' '%''' ActivateEscapeSequences: False Result=> NewFileName
This will replace all of those characters with a whitespace and store the output in a variable called %NewFileName%. Please use this before your Rename file(s) action.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.