[英]Outlook addin know when Send button is pressed
我开始使用C#查看Outlook插件,并想知道单击“发送电子邮件”时如何在我的插件中得到通知。 插件中有可能吗?
我也想知道发送的电子邮件以及其标题,正文和地址。 我是Addin的初学者,完全困惑如何实现此目标。
您可以为此使用Application.ItemSend
事件。 发送的项目将作为参数传递给事件处理程序。 您可以通过尝试将对象MailItem
为MailItem
来检查是否获得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 });
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.