当电子邮件发送成功时,C#Outlook删除事件? [英] C# Outlook Remove event when email sent successfully?

查看:177
本文介绍了当电子邮件发送成功时,C#Outlook删除事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插件外观,当电子邮件发送成功时,我创建一个事件,此代码:

I have a plugin outlook, I create an event when an email sent successfully, this code:

private Outlook.Items _items;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    Outlook.Application application = this.Application;
    _items = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail).Items;
    _items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}

然后,我有用户设置,如果用户未选择,我想删除该事件(Items_ItemAdd).

Then, I have the user setting, and if the user doesn't select, I want to remove that event (Items_ItemAdd).

那我该怎么办?

推荐答案

好吧,跟踪Sent Items文件夹并不是一个好主意. Outlook允许通过跳过Sent Items文件夹来删除已发送的项目.的 DeleteAfterSubmit 属性Outlook项目是一个布尔值,如果在发送时未保存邮件副本,则为True;如果副本已保存在已发送邮件"文件夹中,则为False.因此,如果用户或其他软件(例如VBA宏或加载项)在发送电子邮件之前设置了此属性,则永远不会触发该事件.

Well, tracking the Sent Items folder is not really a good idea. Outlook allows to remove a sent item by skipping the Sent Items folder. The DeleteAfterSubmit property of Outlook items is a Boolean value that is True if a copy of the mail message is not saved upon being sent, and False if a copy is saved in Sent Items folder. So, you will never get the event fired if users or other software like VBA macros or add-ins set this property before sending emails.

更好的方法是处理 ItemSend 事件.

A better way is to handle the ItemSend event of the Application which is fired when a new item is received in the Inbox.

对于Microsoft Outlook处理的每个收到的项目,将触发一次此事件.该项目可以是几种不同的项目类型之一,例如MailItemMeetingItemSharingItem. EntryIDsCollection字符串包含与该项目相对应的条目ID.请注意,此行为与事件的早期版本有所不同,当EntryIDCollection包含自上次触发该事件以来收件箱中收到的所有项目的逗号分隔条目ID列表.

This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem , MeetingItem , or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. Note that this behavior has changed from earlier versions of the event when the EntryIDCollection contained a list of comma-delimited Entry IDs of all the items received in the Inbox since the last time the event was fired.

当新消息到达收件箱时以及在客户端规则处理发生之前,将触发NewMailEx事件.您可以使用EntryIDCollection数组中返回的Entry ID来调用

The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously. You should not assume that after these events fire, you will always get a one-item increase in the number of items in the Inbox.

NewMailEx事件处理程序中,您可以询问用户是否在发送后处理电子邮件,如果不是,则可以简单地设置

In the NewMailEx event handler you may ask users whether to process emails after sending and, if it is not, you can simply set the DeleteAfterSubmit property to true.

这篇关于当电子邮件发送成功时,C#Outlook删除事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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