2016-12-21 7 views
0

회사에서 메일 트래픽을 줄이려면 Outlook 용 사용자 지정 리본 추가 기능을 개발하고 있습니다.C# outlook get attachement

파일을 자동으로 열어서 수신자가 파일을 저장해야하는 위치를 알고 있어야합니다. 그것은 특정 프로그램이기 때문에.

특정 메일 (메일을 두 번 클릭하여 열어 본 메일)의 첨부 파일에 '경로'를 가져 오는 방법은 무엇입니까?

나는 aleady에게 맞춤 검색 버튼이 달린 리본을 가지고 있습니다. 하지만 내가 attachemnts 먼저 필요로 계속할 수 없습니다.

private void Ribbon1_Load(object sender, RibbonUIEventArgs e) 
{ 

} 

private void btnGerbv_Click(object sender, RibbonControlEventArgs e) 
{ 
    Forms.MessageBox.Show("Testing"); 
} 

답변

0

here는 :

private void SaveMailAttachments(Outlook.MailItem mailItem) 
{ 
    Outlook.Attachments attachments = mailItem.Attachments; 
    if (attachments != null && attachments.Count > 0) 
    { 
     for (int i = 1; i <= attachments.Count; i++) 
     { 
      Outlook.Attachment attachment = attachments[i]; 
      if (attachment.Type == Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue) 
      { 
       string filename = Path.Combine(@"d:\", attachment.FileName); 
       attachment.SaveAsFile(filename); 
      } 
     } 
    } 
} 

그리고 here :

private void ThisAddIn_Startup(object sender, System.EventArgs e) 
{ 
    this.Application.NewMail += new Microsoft.Office.Interop.Outlook 
     .ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail); 
} 

private void ThisApplication_NewMail() 
{ 
    Outlook.MAPIFolder inBox = this.Application.ActiveExplorer() 
     .Session.GetDefaultFolder(Outlook 
     .OlDefaultFolders.olFolderInbox); 
    Outlook.Items inBoxItems = inBox.Items; 
    Outlook.MailItem newEmail = null; 
    inBoxItems = inBoxItems.Restrict("[Unread] = true"); 
    try 
    { 
     foreach (object collectionItem in inBoxItems) 
     { 
      newEmail = collectionItem as Outlook.MailItem; 
      if (newEmail != null) 
      { 
       if (newEmail.Attachments.Count > 0) 
       { 
        for (int i = 1; i <= newEmail 
         .Attachments.Count; i++) 
        { 
         newEmail.Attachments[i].SaveAsFile 
          (@"C:\TestFileSave\" + 
          newEmail.Attachments[i].FileName); 
        } 
       } 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     string errorInfo = (string)ex.Message 
      .Substring(0, 11); 
     if (errorInfo == "Cannot save") 
     { 
      MessageBox.Show(@"Create Folder C:\TestFileSave"); 
     } 
    } 
} 
+0

덕분에,이 partialy 내 질문에 대답했다. 지금 직면하고있는 문제는 내가 내 사서함에서 모든 attachemnts를 받고 있다는 것입니다. 나는 opend 메일의 attachemnts 만 필요합니다. – Meerweten