2017-04-03 5 views
0

Ich versuche, die Anlage Datei in einem Outlook-Plugin vor der Datei zu einem mailItem zu verbinden.Hinzufügen Anhänge Ereignis 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; 
}} 

Wenn ich eine neue E-Mail in Outlook zu erstellen, meinen Code Passe mit dieser Methode, aber das Ereignis wird nie ausgelöst, wenn ich eine Befestigung an meine E-Mail hinzufügen.

Jede Idee?

+1

Die Antwort ist hier: [Event-Handler nicht hinzugefügt werden zu neuen Postsendungen] (http://stackoverflow.com/questions/24576890/event-handler-not-being-added-to-new-mail-items) –

+0

Wow ... Ihr Recht! Vielen Dank –

+0

Froh, dass es geholfen hat;) –

Antwort

1

Sie müssen das Quellobjekt auf Klassenebene (global scope) zu erklären, beispielsweise zu verhindern, dass es von der Garbage Collector von 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; 
     } 
    } 
Verwandte Themen