2017-05-23 12 views
1

の[送信済みアイテム]フォルダから送信先の電子メールアドレスを取得するOutlook InteropおよびC#を使用してメール情報を取得してExcelレポートを作成しています。私は送信済みアイテムフォルダから電子メールアイテムリストを持っており、私はメールを送信した電子メールアドレスを取得したい。私は "To"プロパティを見つけましたが、住所ではなく人名のみを返します。Outlook Interop C#

誰でもOutlook.MailItemオブジェクトから電子メールアドレスを返すことができますか? 詳細情報が必要な場合は、私に尋ねることができます。ありがとう!!!!ここで

は、私はプロパティを設定しています私のコードです:MailItemは、受信者のプロパティを持つ

foreach (object mail in mails) 
    //mails is a list from Sent Items folder 
     { 
      if (mail is Outlook.MailItem) 
      { 
       var item = (Outlook.MailItem)mail; 
       //i need the address in provider email 
       var providerEmail = someProperty(????); 
       var name = item.To; 
       var request= "Other Request"; 
       var emailDate= item.ReceivedTime; 
       var status = "Closed"; 
       var responseDate= item.CreationTime; 
       var reportObject = new ReportModel 
       { 
        Email = providerEmail , 
        Name = name, 
        Solicitud = request, 
        EmailDate = emailDate, 
        Status = status, 
        ResponseDate = responseDate 
       }; 
      } 
     } 

答えて

1

、あなたはそれぞれのタイプの受信者を得るためにそれを使用することができます:

  • ccまで
  • Bcc。

recipient.Typeを使用すると、受信者の種類とrecipient.Addressを認識して電子メールアドレスを取得できます。 例:

protected override void getRecepients(MailItem OLitem, StringBuilder toStringBuilder, 
     StringBuilder ccStringBuilder, StringBuilder bccStringBuilder) 
    { 
     try 
     { 
      var recipients = OLitem.Recipients; 
      string parent = string.Empty; 
      foreach (Microsoft.Office.Interop.Outlook.Recipient recipient in recipients) 
      { 
       switch (recipient.Type) 
       { 
        case (int)Microsoft.Office.Interop.Outlook.OlMailRecipientType.olTo: 
         toStringBuilder.Append(recipient.Address + ", "); 
         if (parent == string.Empty) 
         { 
          parent = recipient.Address; 
         } 
         break; 
        case (int)Microsoft.Office.Interop.Outlook.OlMailRecipientType.olCC: 
         ccStringBuilder.Append(recipient.Address + ", "); 
         break; 
        case (int)Microsoft.Office.Interop.Outlook.OlMailRecipientType.olBCC: 
         bccStringBuilder.Append(recipient.Address + ", "); 
         break; 
        default: 
         break; 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      // do something with error 
     } 
    } 
+0

こんにちは、ありがとうございました。私はこのコードを使用しようとしたが、この文字列を親に持つ "/ o = ExchangeLabs/ou = Exchange Administrative Group(FYDIHF23SPDLT)/ cn = Recipients/cn = b2caf13289112522dcc06fb-300070" –

+1

こんにちは、私は問題の解決策を見つけた、それはExchangeService.ResolveName(stringToResolve)で親変数の名前を解決する必要があります、これはアドレス、名前、MailboxTypeなどのいくつかのプロパティを持つコレクションを返します。 ! –