【问题标题】:VSTO Outlook Add-in will not move item another storeVSTO Outlook 加载项不会将项目移动到另一个商店
【发布时间】:2019-07-12 04:57:57
【问题描述】:

我有一个 Outlook 加载项,可以将电子邮件项目移动到另一个邮箱中的另一个文件夹。至少,它曾经这样做过。现在它不再移动它。我编写了另一个测试插件,将电子邮件项目移动到当前用户邮箱中的另一个文件夹并且它确实有效,所以我的问题是,将项目移动到另一个邮箱是否会导致问题?

下面是一些解释代码:

要执行移动到另一个邮箱,代码使用此行为每个邮箱创建存储,

stores = Globals.ThisAddIn.OutlookApplication.GetNamespace("MAPI").Stores;

然后使用 foreach 循环遍历每个商店,

foreach (Outlook.Store store in stores)

获取当前收件箱,以备后用,

destinationMailboxFolderInbox = (Outlook.Folder)store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

如果此商店的 DisplayName 与我指定为目标的商店匹配,它会继续在子文件夹中搜索我想要的商店,

if (store.DisplayName.Equals(destinationMailbox))
{
    foreach (Outlook.Folder myFolder in destinationMailboxFolderInbox.Folders)
    {
        if (myFolder.Name.Equals(destinationMailboxFolder))
        {
            item.Move(myFolder);

问题是,它似乎没有运行最后一个 foreach 循环(遍历文件夹)。

就像我说的,当我将其更改为使用当前用户的邮箱时,它会起作用。当我设置为当前用户可以访问的共享邮箱时,它不起作用。

我还缺少其他步骤吗?

【问题讨论】:

  • 更新:我发现另一个帖子提到了可能相关的内容:It's often not a good idea to modify the contents of a (sub)set of items while looping over them. You could modify your code so that it first identifies all of the items that need to be processed, and adds them to a Collection. Then process all the items in that collection. Basically you shouldn't be removing items from the Inbox while you're looping through its contents. First collect all the items you want to process (in your Inbox loop), then when you're done looping, process that collection of items.
  • 所有项目都失败了吗?还是只是一些?
  • 当你说“似乎没有运行最后一个 foreach 循环”时,这意味着前面的语句 (store.DisplayName.Equals(destinationMailbox)) 返回 false,这意味着 store 的显示名称不同于你期待。
  • 如果所有项目都失败。在测试期间,我在第一个 foreach 循环和第二个 foreach 循环之间添加了一些输出语句。它只显示第一个的输出语句。
  • 明天我会再次检查并确认我在测试期间看到的内容。

标签: c# vsto outlook-addin


【解决方案1】:

此问题是权限问题或错误。我最终没有直接解决,而是开发了一种解决方法。

解决方法是创建一个 Outlook“快速步骤”按钮来移动电子邮件。 Outlook 用户将单击我的 VSTO 编码的加载项按钮以保存附件,然后单击快速步骤按钮将电子邮件移动到文件夹。

【讨论】:

    猜你喜欢
    • 2023-02-24
    • 2017-11-04
    • 2010-11-11
    • 2018-10-28
    • 2020-09-18
    • 2014-05-10
    • 2022-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多