繁体   English   中英

Outlook加载项知道何时按下“发送”按钮

[英]Outlook addin know when Send button is pressed

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

我也想知道发送的电子邮件以及其标题,正文和地址。 我是Addin的初学者,完全困惑如何实现此目标。

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

您没有指定要使用的外接技术,但是正如您提到的C#一样,我假设您使用的是Microsoft.Office.Interop.Outlook

可以捕获EmailItem的send事件。 您可以使用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中提供send事件。 这是参考

更新以包含Dmitry的评论:

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

我不确定您是否使用Web加载项技术,但这是有关发送代码上的WEB Outlook加载项的示例。 主要代码如下:

// 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 });
            }

        });
}

有关更多信息,请参见如何在Office加载项(OWA,Windows Outlook 2016)中发送邮件时挂接事件

如何:使用C#发送之前更改Outlook电子邮件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM