0
Reply

Decrypt an email body using Microsoft Exchange Server API

Anand Hegde

Anand Hegde

Sep 2 2013 4:03 AM
1.4k

Scenario : Am trying to pull the emails from the remote Exchange server and trying to display the details like From, To, Body,Time etc.Here am able to display the above mentioned details, only if the mail is not encrypted.If it is encrypted, am able to access all the details except the Email Body. Email Body is coming as null.So please help me how can I decrypt the mail and get the mail body using any one of the decryption technique(PKI authentication would be good(preferable)).

Am using the following code to get the email item.

                        

ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
            {
                Credentials = new WebCredentials("username", "password")

            };

            ews.AutodiscoverUrl("[email protected]",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;