创建 Outlook MailItem 并保存为其他用户的草稿

发布于 2024-12-17 05:51:57 字数 1321 浏览 0 评论 0原文

我正在尝试创建一个邮件项目并将其保存在其他用户的草稿文件夹中。我可以创建草稿,但它仅保存到我自己的草稿文件夹,而不保存到其他用户。我对其他用户的邮箱有足够的权限。

这是到目前为止我的测试代码:

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪之魂 2024-12-24 05:51:57

好吧,我自己解决了。在“保存”之后,我添加一个“移动”,将其从我的草稿文件夹移动到用户的共享文件夹。所以代码将是:

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()

        .Move(omDrafts)

    End With

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:

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()

        .Move(omDrafts)

    End With
阳光的暖冬 2024-12-24 05:51:57

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 be Outlook.OlDefaultFolders.olFolderDrafts

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文