创建 Outlook MailItem 并保存为其他用户的草稿
我正在尝试创建一个邮件项目并将其保存在其他用户的草稿文件夹中。我可以创建草稿,但它仅保存到我自己的草稿文件夹,而不保存到其他用户。我对其他用户的邮箱有足够的权限。
这是到目前为止我的测试代码:
Dim omApp As New Outlook.Application
Dim omNamespace As Outlook.NameSpace = omApp.GetNamespace("MAPI")
Dim omUser As Outlook.Recipient = omNamespace.CreateRecipient("[email protected]")
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 = "[email protected]"
.To = "[email protected]"
.Subject = "Test"
.Body = "Test email"
.Save()
End With
我做错了什么?
该代码必须适用于 2003 至 2010 年间的所有 Outlook 版本。
I'm trying to create a mailitem and save it in the Drafts folder for an other user. I can create the draft but it only saves to my own draft folder, not for the other user. I have enough rights on the mailbox of the other user.
This is my test code so far:
Dim omApp As New Outlook.Application
Dim omNamespace As Outlook.NameSpace = omApp.GetNamespace("MAPI")
Dim omUser As Outlook.Recipient = omNamespace.CreateRecipient("[email protected]")
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 = "[email protected]"
.To = "[email protected]"
.Subject = "Test"
.Body = "Test email"
.Save()
End With
What am I doing wrong?
The code has to work for all Outlook versions from 2003 to 2010.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我自己解决了。在“保存”之后,我添加一个“移动”,将其从我的草稿文件夹移动到用户的共享文件夹。所以代码将是:
Ok, I've solved it myself. After the "Save" I add a "Move" to move it from my Drafts folder to the user's shared folder. So the code will be:
GetDefaultFolder 始终默认为您的本地默认草稿文件夹。查看 GetSharedDefaultFolder 方法。
您必须将 Recipient 对象传递给此方法 - 您已经为此拥有了 omUser。您还必须传递文件夹类型,该类型应为
Outlook.OlDefaultFolders.olFolderDrafts
GetDefaultFolder always defaults to your local default Drafts folder. Check out the GetSharedDefaultFolder method.
You must pass a Recipient object to this method -- you already have
omUser
for that. You must also pass the folder type, which should beOutlook.OlDefaultFolders.olFolderDrafts