2017-04-03 9 views
0

파일 첨부 전에 maillook에 첨부 파일을 가져 오려고합니다.첨부 파일 이벤트 추가 Outlook 추가 기능

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에서 새 이메일을 작성,이 방법으로 예스 러운 내 코드,하지만 난 내 이메일에 첨부 파일을 추가 할 때, 이벤트는 트리거되지 않습니다.

아이디어가 있으십니까?

+1

을 대답은 여기에 있습니다 : [이벤트 처리기를 추가하지 새 메일 항목] (http://stackoverflow.com/questions/24576890/event-handler-not-being-added-to-new-mail-items) –

+0

와우 ... 당신의 권리! 대단히 감사합니다 –

+0

다행히 도왔습니다;) –

답변

1

당신은 예를 들어, 가비지 컬렉터에 의해 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; 
     } 
    }