I’m trying to save the outlook email item to physical drive through InvokeCode activity but getting below error all the time:
Outlook version:2013
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ----> System.Runtime.InteropServices.COMException: Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
at Microsoft.Office.Interop.Outlook._MailItem.SaveAs(String Path, Object Type)
at UiPathCodeRunner_cf009ab11a6e4202bc242f7f11192581.Run(String
Have you checked Event Viewer logs? Did you see anything interesting? I have two candidates for this error at the moment;
1-x86 to x64 compatibility which is a weaker candidate,
2-Antivirus/Security/Policy restrictions
I will inform you if I find a solution, please text me back if you find anything interesting
@2aozturk Thanks
I guess the issue is with outlook security. I don’t have any error logs in viewer but will try one more time and see if I can trace back further.
I have a security log in event viewer like Security Center failed to validate caller with error DC040780 it seems like an antivirus issue may be happening.
Have you tried Save or Send methods at all? Both working in my case, only SaveAs is failing…
I tried using SaveAs again and can see below error logged in the event viewer
System.IO.IOException: The write operation failed, see inner exception. —> System.ServiceModel.CommunicationObjectAbortedException: The operation cannot be completed because the pipe was closed.
I think we both struggle from the same reason then
I’ve tried same functionality with vba codes and saw the error mentioned in my previous post.
Below is the code, you can run it within excel vba designer.
Note: Outlook must be left opened during the runtime of this code
Public Sub create_then_save_email()
On Error GoTo lbl_error
Dim OutApp As Outlook.Application
Set OutApp = GetObject(, "Outlook.Application")
Dim email As Outlook.MailItem
Set email = OutApp.CreateItem(0)
email.To = "anemail@address.com"
email.Subject = "Test Subject"
email.HTMLBody = "Test <b>HTML</b> Body"
'Application.Wait DateAdd("s", 3, Now)
Dim targetFolder As String, targetFile As String
targetFolder = "C:\NewFolder"
targetFile = targetFolder & "\" & "SavedEmail.msg"
create_folder targetFolder
MsgBox "E-mail will be saved saved at when you confirm this popup => " & targetFile, vbExclamation
email.SaveAs targetFile
MsgBox "E-mail saved at [" & targetFile & "] please check the location...", vbInformation
Exit Sub
lbl_error:
If Err <> 0 Then
MsgBox Err.Description, vbCritical
End If
End Sub
one more you should also past this code into vba designer, sorry
Sub create_folder(s_directory As String)
Set OFSO = CreateObject("Scripting.FileSystemObject")
dirExists = OFSO.FolderExists(s_directory)
'Set targetFolder = "C:\NewFolder"
If Not dirExists Then
MkDir s_directory
End If
I have my code written in VB.Net. I tried running the same code on my laptop and it is working fine without any issue. Looks like an outlook security issue on client domain.
Hi, problem was related with a computer policy, we’ve set the following property by adding robot process as trusted process or you can simple set this policy to Automatically approve with your own risk