以下代码段可在Windows 10 / Outlook 2013中使用。
在Windows 10 / Outlook 2016中,我在.send
行出现错误:
运行时错误-2147219712(80040600):`操作失败。
消息传递接口返回了未知错误。如果问题仍然存在,请重新启动Outlook。无法解析收件人。
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
在Outlook 2016中,MsgBox
表示“是”,用户界面打开了一个用于新邮件对象的窗口,并且在那里格式正确的电子邮件地址在那里。
当我单击“收件人”字段,然后单击“发送”时,将发送电子邮件。
Outlook 2013产生一个MsgBox
表示“假”,但是无论如何,它都会在用户干预下发送电子邮件。
我如何在Outlook 2016中解决此问题以在没有用户干预的情况下发送电子邮件?
答案 0 :(得分:1)
0x80040600
是MAPI_E_CORRUPT_STORE
。如果是PST存储,则很可能意味着PST文件已损坏-尝试运行scanpst.exe。如果是缓存的Exchange存储,请尝试删除OST文件并重新启动Outlook,它将重新生成OST文件。
可以在OutlookSpy中查找MAPI错误代码(单击OutlookSpy功能区上的“错误代码查找”)。