2012-02-28 4 views
-1

こんにちは私はoutlookが添付ファイルを送信し、送信されたメールの受信者の件名を取得したい...私はOutlookのデフォルトのフォルダでそれを得ることができます。 メールが送信される前に、VSTOによって送信されたメールを取得するにはどうすればよいですか。outlook sent mails

は、今私はあなたがここでやろうとしている正確に何かわからないので、

namespace OutlookAddInAttachment 
{ 
    public partial class ThisAddIn 
    { 
     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 SentMail = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox); 
     Outlook.Items SentMailItems = SentMail.Items; 
     Outlook.MailItem newEmail = null; 
     //SentMailItems = SentMailItems.Restrict("[Unread] = true"); 
     try 
     { 
      foreach (object collectionItem in SentMailItems) 
      { 
       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"); 
      } 
     } 
    } 

答えて

1

行っています。

あなたは、受信ボックスに新しい受信メールを待ち受けている状態で、送信済みのアイテムのみを含む送信済みアイテムフォルダをスキャンします。

あなたが何をしようとしていることはあなたが必要なもの、新しいメールのattachemntsが送信されて切片である場合は、それが送信されています前に、アクションでそれをキャッチすることができますItemSendイベント、次のとおりです。

public partial class ThisAddIn 
{ 

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

private void ThisApplication_ItemSend(object item, bool cancel) 
{ 
    Outlook.MailItem newEmail = item as MailItem; 
    if (newEmail != null) 
    { 
     foreach (var attachment in newEmail.Attachments) 
     { 
      attachment.SaveAsFile(@"C:\TestFileSave\" + attachment.FileName); 
     } 
    } 
} 

} 
関連する問題