我正在尝试创建mailitem并将其保存在其他用户的“草稿”文件夹中。我可以创建草稿,但它只保存到我自己的草稿文件夹,而不是其他用户。我对其他用户的邮箱拥有足够的权限。
到目前为止,这是我的测试代码:
Dim omApp As New Outlook.Application
Dim omNamespace As Outlook.NameSpace = omApp.GetNamespace("MAPI")
Dim omUser As Outlook.Recipient = omNamespace.CreateRecipient("otheruser@mail.com")
omUser.Resolve()
If Not omUser.Resolved Then
MsgBox("Could not login.")
End If
Dim omDrafts As Outlook.MAPIFolder = omNamespace.GetSharedDefaultFolder(omUser, Outlook.OlDefaultFolders.olFolderDrafts)
Dim omMailItem As Outlook.MailItem = CType(omDrafts.Items.Add, Outlook.MailItem)
With omMailItem
.SentOnBehalfOfName = "otheruser@mail.com"
.To = "bill@gates.com"
.Subject = "Test"
.Body = "Test email"
.Save()
End With
我做错了什么?
该代码必须适用于2003年至2010年的所有Outlook版本。
答案 0 :(得分:1)
好的,我自己解决了。在“保存”后,我添加了一个“移动”,将其从我的“草稿”文件夹移动到用户的共享文件夹。所以代码将是:
Dim omApp As New Outlook.Application
Dim omNamespace As Outlook.NameSpace = omApp.GetNamespace("MAPI")
Dim omUser As Outlook.Recipient = omNamespace.CreateRecipient("otheruser@mail.com")
omUser.Resolve()
If Not omUser.Resolved Then
MsgBox("Could not login.")
End If
Dim omDrafts As Outlook.MAPIFolder = omNamespace.GetSharedDefaultFolder(omUser, Outlook.OlDefaultFolders.olFolderDrafts)
Dim omMailItem As Outlook.MailItem = CType(omDrafts.Items.Add, Outlook.MailItem)
With omMailItem
.SentOnBehalfOfName = "otheruser@mail.com"
.To = "bill@gates.com"
.Subject = "Test"
.Body = "Test email"
.Save()
.Move(omDrafts)
End With
答案 1 :(得分:0)
GetDefaultFolder始终默认为本地默认的“草稿”文件夹。查看GetSharedDefaultFolder方法。
您必须将Recipient对象传递给此方法 - 您已经拥有omUser
。您还必须传递文件夹类型,该类型应为Outlook.OlDefaultFolders.olFolderDrafts