Can't open saved msg files

I’ve got a process where I am having to extract data from saved .msg files that are saved from Office365Message emails, however neither the bot nor myself as a user can access the files when they are downloaded using the invoke code that I have in place. I get this message -

Does anyone know a workaround to get this sorted? I’ve tried running a VBScript on the .msg file and it throws the same error as the attached picture. This shouldn’t really be a problem, but it is for some reason.

@b.forbes,

Looks like there is something not write with the code you are using to save the mail message.

Any specific reason not to out of the box activity for this task - Activities - Save Mail Message (uipath.com)

If you can try using this activity to save and try to open the saved file.

Thanks,
Ashok :slight_smile:

I tried to use both the Save Mail Message and Save Attachments activities and I got the error “Access to Path: XXX is denied”. The user account the bot uses has full access to all folders so I am not sure why these activities do not work.

To check if write access is present on a file for the UiPath Robot user, Write a code in an “Invoke Code” activity.

Arguments :

Name : path
Direction : In
Type : String

Name : result
Direction : Out
Type : Boolean
Value : res

Code:

Dim writeAllow As Boolean = False
Dim writeDeny As Boolean = False
Dim dInfo As New DirectoryInfo(path)
Dim accessControlList As System.Security.AccessControl.DirectorySecurity = dInfo.GetAccessControl()
If(accessControlList Is Nothing) Then
result = False
Else
Dim accessRules As System.Security.AccessControl.AuthorizationRuleCollection = accessControlList.GetAccessRules(True, True,GetType(System.Security.Principal.SecurityIdentifier))
If accessControlList Is Nothing Then
result = False
Else
For Each rule As System.Security.AccessControl.FileSystemAccessRule In accessRules
If (System.Security.AccessControl.FileSystemRights.Write And rule.FileSystemRights) <> System.Security.AccessControl.FileSystemRights.Write Then Continue For
If rule.AccessControlType = System.Security.AccessControl.AccessControlType.Allow Then
writeAllow = True
ElseIf rule.AccessControlType = System.Security.AccessControl.AccessControlType.Deny Then
writeDeny = True
End If
Next
End If
End If
result = writeAllow AndAlso Not writeDeny

Try this and check if bot really have the access or not.

Thanks,
Ashok :slight_smile:

One more thing, Do you indicate your file with an extension, like test.msg ? If we indicate file without extension and there is a folder which name is same, this error will be thrown.

Thanks,
Ashok :slight_smile:

The bot manages to save attachments from other emails (excel files) in the same folder without issue, should it be able to do that if it didn’t have adequate permissions?

Yes I have tried with attachment name and extension and I am still seeing the same issue.

If this is the case, clearly, it’s not permission issue!

Can you try to save the mail from outlook manually at the same path and try to open it?

Just a thought if the .msg being saved is unable to opened by the outlook version.

Yes if I save it manually I can open the .msg file and see the original email with the attachment.

I will add, I am experiencing the same issue when using Studio on my local machine and in the client virtual machine, so it’s not just a virtual machine issue I don’t think.

How about this?

Cheers

Implemented those Invoke Method activities and still seeing the same issue

image

I experienced such problem with Outlook and MSG file in past.

Scenario is as follows:
1/ I can open the MSG file only once.
2/ After closing the MSG file window and retry openning the same MSG file I get the same message.

Checking openned files shows the MSG file is held by OUTLOOK.EXE
image

Only option to release it is close outlook.

Cheers

P.S. This only happens when Outlook is already running when I am openning the MSG file. Openning MSG file when Outlook is NOT running doesn’t hold the file, i.e. after closing the MSG file I can open it again.

P.P.S. So in your case the solution would be terminating Outlook process before openning MSG file.

I tried adding a Kill Process activity for outlook 5s after downloading the file, however the issue still persists when I try to open the file.

Then try downloading “OpenedFilesView” and check what process is holding the file.
Cheers

Is it possible with save Mail Message and office365 to save as .msg. In the past and for me the present, we were only able to save to .eml and use those files without any issue. Maybe this also works for you?

This did not work unfortunately. I ended up having to get the client to change the emails to not included a forwarded outlook email. This allowed me to use the Save Attachments acitivity. Not a solution, but a workaround. Would be good if there was something that could be done about this by UiPath but I feel it is such a niche issue it probably won’t be addressed.

1 Like