vbaoutlookoutlook-2016

How do I resolve Runtime Error -2147219712 (80040600):` The operation failed


The following code snippet works in Windows 10 / Outlook 2013.

In Windows 10 / Outlook 2016 I get an error at the .send line:

Run-time error -2147219712 (80040600):` The operation failed.

The messaging interfaces have returned an unknown error. If the problem persists, restart Outlook. Cannot resolve recipient.

Option Explicit
Sub email_test()
Dim objOutlookApp               As Outlook.Application
Dim objOriginalItem             As Outlook.MailItem
Dim objNewItem                  As Outlook.MailItem
Dim objInspector                As Outlook.Inspector
Dim objRecipient                As Outlook.Recipient
Dim strEmailAddress             As String
Dim strSubject                  As String

Set objOutlookApp = GetObject(, "Outlook.Application")
Set objInspector = objOutlookApp.ActiveInspector
'Set objOriginalItem so that it can be referenced
Set objOriginalItem = objInspector.CurrentItem
'Set objNewItem to create the new message.
Set objNewItem = objOutlookApp.CreateItem(0)
'Store the original body into the new item body
'Note:  objNewItemBody was altered by code not shown here
objNewItem.Body = objOriginalItem.Body
'Note: strEmailAddress was altered by code not shown here
strEmailAddress = "unique_ name@hotmail.com"
Set objRecipient = objOutlookApp.Session.CreateRecipient(strEmailAddress)
objRecipient.Resolve
MsgBox ("The objrecipient.resolved status is: " & objRecipient.Resolved)
'Set the fields of the MailItem.  Note:  objNewItem.Body was previously set
With objNewItem
    .Display
    .Subject = objOriginalItem.Subject
    .To = objRecipient
        'Loop through the attachments in objOriginalItem
        'Save them to the user's temp folder.
        'Attach them to objNewItem.
    .Send
End With

EXUNT:
Set objOutlookApp = Nothing
Set objOriginalItem = Nothing
Set objNewItem = Nothing
Set objInspector = Nothing

End Sub

In Outlook 2016 the MsgBox indicates "True", The User Interface has a window open for the new mail object and the properly-formatted Email address is there.

When I click on the "To" field and then click "Send", the Email is sent.

Outlook 2013 yields a MsgBox indicating "False", but it sends the eMail with user intervention anyway.

How do I resolve this in Outlook 2016 to send the Email without user intervention?


Solution

  • 0x80040600 is MAPI_E_CORRUPT_STORE. In case of a PST store, that most likely means the PST file is corrupted - try to run scanpst.exe against it. In case of a cached Exchange store, try to delete the OST file and restart Outlook - it will rebuild the OST file.

    MAPI error codes can be looked up in OutlookSpy (I am its author) - click "Error Code Lookup" on the OutlookSpy ribbon.