VSTO Outlook: 区分手动和自动发送

huangapple go评论74阅读模式
英文:

VSTO Outlook: Differenciate between a manual and automatic send

问题

ItemSend事件是否由从撰写窗口发送消息引发,还是由Outlook自动执行的发送(例如,在发件箱中的消息被发送时)而触发,是否有办法识别?

英文:

Is there any way to recognize if the ItemSend event is fired as a result of sending a message from the compose window or as a result of an automatic send performed by Outlook itself (e.g. when messages in the outbox are sent)?

答案1

得分: 1

No, ItemSend事件不提供此类信息。您还可以查找Outlook项目的Send事件,它在用户选择项目的“Send”操作或对项目调用“Send”方法时触发,这是父对象的一个实例。要处理项目级事件,您可以实现检查员包装器并跟踪每个检查员中的项目级事件。这样,您将了解何时何地触发事件(如果在之前打开了任何检查员)。

> 当收件箱中的消息被发送)

这两个事件(ItemSendSend)在项目提交并移动到Outbox文件夹之前触发。但您可以尝试检查项目的父文件夹,但这不能为您提供明确的答案。

如果您确实需要知道用户何时单击“Send”按钮,可以考虑使用Windows API技术,如子类化,在Outlook中检测“Send”按钮的点击。相同的机制也可用于处理Outlook中的键盘快捷键。

英文:

No, the ItemSend event doesn't provide such information. Also you may find the Send event of Outlook items working the same, it is fired when the user selects the Send action for an item, or when the Send method is called for the item, which is an instance of the parent object. For handling the item-level events you can Implement a wrapper for inspectors and track item-level events in each inspector. So, that you will be aware when and when events are fired (if any inspector was opened before).

> when messages in the outbox are sent)

Both events (ItemSend and Send) are fired when the item is submitted and before moved to the Outbox folder. But you may try to check the parent folder of the item, but that can't give you any definitive answer.

If you really need to know when the user clicked the Send button you may consider using clicks on the Send button in Outlook by using Windows API techniques such as subclassing. The same mechanism can be used for handling keyboard shortcuts in Outlook.

答案2

得分: 1

使用MailItem.Send事件代替Application.ItemSend事件。您可以捕获Application.Inspectors.NewInspector事件以钩入新的Inspector,然后在Inspector.CurrentItem上设置事件处理程序。请记住,可以同时打开多个检查器,当检查器关闭时(Inspector.Close事件)需要取消订阅事件。您可以对内联项目(Explorer.InlineResponse/InlineResponseClose事件)执行相同的操作。

请注意,Application.ItemSend事件在用户或以编程方式发送消息时触发,当项目在异步消息提交后的某个时候从发件箱文件夹中移出时会触发。

您可以查看OutlookSpy中的事件触发情况以及时间(我是其作者)- 例如,单击Application按钮,转到事件选项卡,查看事件触发情况。

英文:

Instead of using Application.ItemSend event, use MailItem.Send event. You can trap Application.Inspectors.NewInspector event to hook into new Inspector, then set up event handler on Inspector.CurrentItem. Keep in mind that there can be multiple inspectors open, and you'd need to unsubscribe from the events when the inspector is closed (Inspector.Close event). You can do the same for the the inline items (Explorer.InlineResponse/InlineResponseClose events).

Keep in mind that Application.ItemSend event fires when a message is sent either by the user or programmatically, it does not fire when an item is moved away from the Outbox folder after asynchronous message submission completes some time later.

You can see which events fire and when in OutlookSpy (I am its author) - e.g., click Application button, go to the Events tab and see events fire.

huangapple
  • 本文由 发表于 2023年4月11日 03:32:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980129.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定