【问题标题】:Outlook addin know when Send button is pressedOutlook 插件知道何时按下发送按钮
【发布时间】:2019-03-03 05:40:33
【问题描述】:

我开始使用 C# 查看 Outlook 插件,并想知道单击“发送电子邮件”时如何在我的插件中获得通知。这可以在插件中使用吗?

我还想知道发送的电子邮件及其标题、正文和地址。我是插件的初学者,完全不知道如何实现这一点。

【问题讨论】:

标签: c# .net outlook outlook-addin


【解决方案1】:

您可以为此使用Application.ItemSend 事件。正在发送的项目将作为参数传递给您的事件处理程序。您可以通过尝试将对象强制转换为 MailItem 来检查您是否获得了 MailItem 对象(您也可以拥有 MeetingItem 等)。

【讨论】:

    【解决方案2】:

    您没有指定您使用的是什么插件技术,但正如您提到的 C#,那么我假设您使用的是 Microsoft.Office.Interop.Outlook

    可以捕获EmailItem 的发送事件。您可以使用 Inspector 检索 EmailItem 对象并访问其内容。

    示例代码:

        private void Inspectors_NewInspectorEvent(Outlook.Inspector inspector)
        {
            var currentAppointment = inspector.CurrentItem as Outlook.MailItem;
            ((Outlook.ItemEvents_10_Event)currentAppointment).Send += ThisAddIn_Send;
        }
    
        private void ThisAddIn_Send(ref bool Cancel)
        {
            //Handle send event
        }
    

    如果您使用 Office.js 创建 Web 加载项,则发送事件目前仅在 Office365 OWA 中可用。这是reference

    更新以包含 Dmitry 的评论:

    您应该使用Application.Itemsend,然后您需要检查正在发送的对象是否是电子邮件。

    【讨论】:

    • 绝对没有理由使用 MailItem.Send 事件 - 您需要跟踪每个可能发送的 MailItem 对象。您上面的代码错过了在检查器中未打开的情况下发送的消息 - 用户可以内联回复/转发电子邮件。使用 Application.ItemSend 事件。
    【解决方案3】:

    我不确定您是否使用 Web 插件技术,但这里有一个关于 WEB Outlook add-in on send code 的示例。主要代码如下:

    // Check if the subject should be changed. If it is already changed allow send, otherwise change it.
    // <param name="subject">Subject to set.</param>
    // <param name="event">MessageSend event passed from the calling function.</param>
    function subjectOnSendChange(subject, event) {
        mailboxItem.subject.setAsync(
            subject,
            { asyncContext: event },
            function (asyncResult) {
                if (asyncResult.status == Office.AsyncResultStatus.Failed) {
                    mailboxItem.notificationMessages.addAsync('NoSend', { type: 'errorMessage', message: 'Unable to set the subject.' });
    
                    // Block send.
                    asyncResult.asyncContext.completed({ allowEvent: false });
                }
                else {
                    // Allow send.
                    asyncResult.asyncContext.completed({ allowEvent: true });
                }
    
            });
    }
    

    更多信息请看, How to hook event on sending mail in Office add-in (OWA, Windows Outlook 2016)

    How To: Change an Outlook e-mail message before sending using C#

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多