シナリオ : リモート Exchange サーバーから電子メールを取得しようとしており、From、To、Body、Time などの詳細を表示しようとしています。メールが暗号化されていない場合にのみ、上記の詳細を表示できます。暗号化されているため、メール本文以外のすべての詳細にアクセスできます。メール本文が null として送信されます。そのため、いずれかの復号化手法を使用してメールを復号化し、メール本文を取得する方法を教えてください (PKI 認証が適切です (推奨))。
次のコードを使用してメール アイテムを取得しています。
ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
{
Credentials = new WebCredentials("username", "password")
};
ews.AutodiscoverUrl("firstname.lastname@company.com",RedirectionUrlValidationCallback);
object o = ews.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
FindItemsResults<Item> findResults = ews.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
foreach (EmailMessage message in findResults.Items.Take(10))
{
//MailMessage smtpmsg = message as MailMessage;
mails.Rows.Add(message.Id.UniqueId, message.From.Name, message.Subject, message.DateTimeSent);
}
To display the body am using the following code :
PropertySet emailPropSet = new PropertySet(); emailPropSet.RequestedBodyType = BodyType.Text; emailPropSet.BasePropertySet = BasePropertySet.FirstClassProperties; EmailMessage message = EmailMessage.Bind(ews, new ItemId(uniqueId), emailPropSet);
message.Load();
lblFrom.Text = message.From.ToString();
lblSubject.Text = message.Subject;
lblBody.Text = message.Body.Text;