Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Connecting to Exchange WebService and Storing Item into outlook Folder.

$
0
0

Hi,

I have outlook configured with email id  secretary@company.com         There is another email A/C on Exchange Server boss@company.com

I have an C# 3.5, Outlook addin installed on secretary's Machine.

We want that addin should be able to access A/C boss@company.com and get some mails from that A/C to Read.  (We know that in outlook we can share mailbox, but we don;t want to use that)

So I wrote Exchange WebService to connect to boss A/C and get some mails.  I wrote few lines of code with was able to retrieve mail. code is as below.

Added Reference to Microsoft.Exchange.WebServices From C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll

Code as below.

ExchangeService xService = new ExchangeService();
xService.Url = new Uri(@"https://mail.xxxxxxx.com/EWS/Exchange.asmx");
xService.UseDefaultCredentials =false; 
xService.Credentials =new NetworkCredential("test1", "xxxxx", "xxxxx.com");
FindItemsResults<Item> findResults = xService.FindItems(WellKnownFolderName.Inbox, new ItemView(100));
MessageBox.Show(findResults.Count().ToString());

   foreach (var x in findResults)
            {
                x.Load();
                EmailMessage m = EmailMessage.Bind(xService, x.Id);
                m.Load();Outlook.MailItem mic = (Outlook.MailItem)(this.Application.CreateItem(Outlook.OlItemType.olMailItem));
                mic.To = m.ToRecipients[0].Address;
                //Stuck here.
                // To much of code to write, reading each property from EmailMessage and Assigning it to OutlookMailItem.
                // Much of code to write if attachments are there.
                // Why there is no simple way?
            }


? QUESTION ?

1.  Is there a way to convert EmailMessage to Outlook.MailItem.  I wish i could do a simple thing like outlook.MailItem =EmailMessage.
2.  Is there a way to save EmailMessage as an item into one of the Outlook Folder directly.  (In current Outlook Instance)
3.  Is there a way that xService.FindItems returns items in outlook's .MSG format.   or any method which can create .MSG file from EmailMessage


Regards


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>