添加附件事件Outlook AddIn
问题描述:
我试图在文件附加到mailItem之前获取Outlook插件中的附件文件。添加附件事件Outlook AddIn
private void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
if (Inspector.CurrentItem is Outlook.MailItem)
{
Outlook.MailItem mail = (Outlook.MailItem)Inspector.CurrentItem;
Inspector.AttachmentSelectionChange += Inspector_AttachmentSelectionChange;
Application.AttachmentContextMenuDisplay += Application_AttachmentContextMenuDisplay;
mail.BeforeAttachmentAdd += Mail_BeforeAttachmentAdd;
mail.AttachmentAdd += Mail_AttachmentAdd;
mail.BeforeAttachmentWriteToTempFile += Mail_BeforeAttachmentWriteToTempFile;
mail.BeforeAttachmentSave += Mail_BeforeAttachmentSave;
}}
当我在Outlook中创建一个新的电子邮件,我的代码过时通过这种方法,但是当我一个附件添加到我的邮箱的事件从来没有发射。
有什么想法?
答
您需要声明类级别(全球范围)源对象,以防止它被垃圾收集器dwiping,例如:
Outlook.MailItem mail = null;
Outlook.Inspector inspector = null;
private void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
inspector = Inspector;
object oMail = inspector.CurrentItem;
if (oMail is Outlook.MailItem)
{
mail = (Outlook.MailItem)oMail.CurrentItem;
inspector.AttachmentSelectionChange += Inspector_AttachmentSelectionChange;
Application.AttachmentContextMenuDisplay += Application_AttachmentContextMenuDisplay;
mail.BeforeAttachmentAdd += Mail_BeforeAttachmentAdd;
mail.AttachmentAdd += Mail_AttachmentAdd;
mail.BeforeAttachmentWriteToTempFile += Mail_BeforeAttachmentWriteToTempFile;
mail.BeforeAttachmentSave += Mail_BeforeAttachmentSave;
}
}
答案是在这里:不添加事件处理程序到新的邮件项目](http://*.com/questions/24576890/event-handler-not-being-added-to-new-mail-items) –
哇...你的权利!非常感谢 –
很高兴帮助;) –