自定义Outlook插件未按预期下载 [英] Custom outlook plug in not downloading as expected

查看:85
本文介绍了自定义Outlook插件未按预期下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个自定义代码,以便无论何时收到带有附件的电子邮件,都必须将其下载到共享位置,并且每天都会收到电子邮件.

I have written a custom code such that when ever an email arrives which has an attachment,it must get downloaded into a shared location, and email arrives daily.

当我每天打开笔记本电脑时,如果我不打开并且有连续的邮件(带有附件)并且没有下载,则可以正常工作,例如,当我星期一打开笔记本电脑时,我有3封带有附件的邮件(来自星期六,星期日,星期一的satu).

When I open my laptop daily it's working fine if i don't open and if there are continuous mails (with attachments) and it is not getting downloaded for example, when i open my laptop on monday I have 3 mails with attachment (from satu, sunday, monday).

它不是从星期一下载最新报告,而是在周六仍向我显示相同的报告.

It is not downloading the latest report from monday it is still showing me same report on saturday.

这是我的代码.

private void ThisAddIn_Startup(object sender,System.EventArgs e) {
    outlookNameSpace=this.Application.GetNamespace("MAPI");
    inbox=outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
    items=inbox.Items;
    items.ItemAdd +=new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd);
}
private void items_ItemAdd(object Item) {
    Outlook.Items inboxitems;
    const string destinationDirectory=@"\\Service Now\";
    Outlook.MailItem newEmail=null;
    inboxitems=inbox.Items.Restrict("[Unread] = true");
    try {
        foreach (object collectionItem in inboxitems) {
            newEmail=collectionItem as Outlook.MailItem;
            if (newEmail !=null) {
                if (newEmail.Attachments.Count > 0) {
                    for (int i=1; i <= newEmail.Attachments.Count; i++) {
                        if (newEmail.Attachments[i].FileName.Contains("Logic")) {
                            //   String Des= destinationDirectory.Remove(0, 1);
                            newEmail.Attachments[i].SaveAsFile(destinationDirectory + newEmail.Attachments[i].FileName);
                            //  MessageBox.Show("Hurry");
                        }
                    }
                }
            }
        }
    }catch (System.Exception ex) {
        MessageBox.Show(""+ex);
    }
}

推荐答案

您是否尝试调试代码?

我在代码中看到以下情况:

I see the following conditions in the code:

inboxitems= inbox.Items.Restrict("[Unread] = true");

if (newEmail.Attachments[i].FileName.Contains( "Logic"))

确保电子邮件符合上述条件.

Make sure that emails corresponds to the conditions shown above.

请注意,一次将大量项目添加到文件夹中(超过16个)时,不会触发Items类的ItemAdd事件.

Be aware, the ItemAdd event of the Items class is not fired when a large number of items are added to the folder at once (more than 16).

P.S.尝试查看 MarkForDownload Outlook项目的属性-一个 OlRemoteStatus 值,用于确定远程用户接收到的商品.

P.S. Try to check out the MarkForDownload property of Outlook items - an OlRemoteStatus value that determines the status of an item once it is received by a remote user.

这篇关于自定义Outlook插件未按预期下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆