Hi
We are doing an automation where we receive pdf file over email.
Few of them may contains special characters and those emails are not getting saved. (with no error)
is there any way to handle this issue?
Hi
We are doing an automation where we receive pdf file over email.
Few of them may contains special characters and those emails are not getting saved. (with no error)
is there any way to handle this issue?
Hi @pankajdhane ,
Save Mail Attachments uses the original attachment name directly.
If the name contains Windows-invalid filename characters. Then, Windows rejects the file path β UiPath often doesnβt throw a clear error β file simply doesnβt get saved.
So we must rename/sanitize the filename before saving.
Steps to fix this issue in UiPath:
STEP 1 β Donβt use βSave Mail Attachmentsβ
Because it uses the original name (which may be invalid), so it fails silently.
STEP 2 β Instead loop through each attachment
Use a For Each activity:
STEP 3 β Get the attachment name
Use an Assign activity:
rawName = attachment.Name
STEP 4 β Clean the name (remove bad symbols)
Replace invalid characters with _ so Windows accepts the name.
Use Assign activity:
safeName = rawName.Replace(β\β,β_β).Replace(β/β,β_β).Replace(β:β,β_β) _
.Replace(β*β,β_β).Replace(β?β,β_β).Replace(ββββ,β_β) _
.Replace(β<β,β_β).Replace(β>β,β_β).Replace(β|β,β_β)
This step makes the filename safe.
STEP 5 β Create the final path
Use Assign:
fullPath = pdfFolder + "\" + safeName
Now we have a clean path with no bad characters.
STEP 6 β Save with βInvoke Methodβ
Use an Invoke Method activity:
TargetObject: attachment
MethodName: SaveAsFile
Add parameter:
This saves the file correctly using your cleaned name.
In-Short:
Save Mail Attachments fails because the file name contains illegal characters. So we clean the filename first, then save it using Invoke Method β SaveAsFile.
Kindly mark it as accepted solution, if this works and resolves your issue. Thanks in advance ![]()
Hi @pankajdhane
Issue is coming because special character are not saved try this firstly clean the file name
Try this
cleanFileName = System.Text.RegularExpressions.Regex.Replace(
attachment.Name,
β[\/:*?ββ<>|]β,
β_β
)
Regards
Nishi
Hi @pankajdhane
This happens because some attachments have characters that are invalid in Windows file names, so they donβt get saved and no error is thrown.
You need to sanitize the attachment name (remove or replace special characters like / \ : * ? " < > |) before saving, or save first and then rename the file to a safe name.
HI @Harshini_Here , target object giving error message
Generally it would save with scpecial characters alsoβ¦are the attachments encrypted?
to verify can you send a sample email with special characters yourself and check..looks like the attachment encryption issue or something else
cheers
Hi @pankajdhane
Run in Debug and check if all attachments are counted.If the count is correct, then the issue is the file name.Use Save Attachments, but before saving, rename the attachment by replacing special characters with β_β.
Read the attachment name, clean it with a Replace or regex, then save it.
Happy Automation
we can read the file name and change it but how can we download it?
change will not be applied to attachment without saving the files
i think might be this happen due to another issue not by special char. pls try to debug and extract all attachment names, or use Try Catch to see if an error is thrown(Share error screenshot).
OR
Then read all attachment names into a list, check each name for special characters using an array of invalid characters.
Happy Automation
issue has been resolved.thanks all.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.