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

时间:2018-09-27 10:20:25

标签: c# .net outlook outlook-addin

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

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

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

您没有指定正在使用的外接程序技术,但是正如您提到的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中提供send事件。这是reference

更新为包含Dmitry的评论:

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

答案 2 :(得分:0)

我不确定您是否使用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#

相关问题