<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><category>pcsoft.us.windev</category><copyright>Copyright 2026, PC SOFT</copyright><lastBuildDate>8 May 2017 15:46:00 Z</lastBuildDate><pubDate>4 May 2017 12:19:00 Z</pubDate><description>Hi guys.&#13;
&#13;
I am using Exchange WebServices to access multiple mailboxes on an Exchange server. Because I want my application to run as a system service, I cannot - and don't want - to use the built in functions as it relies on outlook and I don't want to create a million Outlook profiles... This solution also has the benefit of running from a non-domain connected computer. If it was possible to get working thoroughly, it could be used as the basis for an archival tool or a way to backup multiple Exchange online accounts (o365)&#13;
&#13;
I can log in just fine, list folder contents, load individual messages, save attachments etc. All good.&#13;
However, What I really want to do is to save the messages as .EML files. According to the EWS API this can only be done by saving the MIMECONTENT of the message as a whole.&#13;
&#13;
Here is my code (Most of which works great), hope fully someone will find this useful&#13;
The bit that doesn't work is the saving of the mimecontent near the end.&#13;
&#13;
If anyone has done this successfully, I'd be delighted if you could share&#13;
&#13;
Cheers, Bosh&#13;
ServiceEWS is an ExchangeService(ExchangeVersion.Exchange2013,TimeZoneInfo.Utc) ServiceEWS.Credentials = new WebCredentials("login","pw","WDomain") //Note. Wdomain is the NT style domain name, not the public domain name ServiceEWS.Url = new Uri("https://mail.yourdomain.com/EWS/Exchange.asmx"); //Test read of ten messages in Inbox clInbox is a Folder(ServiceEWS) clInbox &lt;- Folder.Bind(ServiceEWS,WellKnownFolderName.Inbox) clFindresults is a 'FindItemsResults&lt;Microsoft.Exchange.WebServices.Data.Item&gt;' clFindresults &lt;- ServiceEWS.FindItems(WellKnownFolderName.Inbox,new ItemView(10)) clMail is an EmailMessage(ServiceEWS) FOR ALL i OF clFindresults.Items xs is an 'Collection&lt;Microsoft.Exchange.WebServices.Data.PropertyDefinitionBase&gt;' xs.add(ItemSchema.Attachments) clMail &lt;- EmailMessage.Bind(ServiceEWS,i.id, new PropertySet(BasePropertySet.IdOnly, xs)) clMail.Load() Trace(clMail.Subject) END bMoreItems is a boolean = True ipagesize is int = 50 IOffset is int nIIter is int nIDspCnt is int //Search for subfolders of Inbox vi is a FolderView = Null Scfilt is a SearchFilter = Null Scfilt &lt;- new SearchFilter.IsGreaterThan(FolderSchema.TotalCount, 0); vi &lt;- new FolderView(ipagesize,IOffset) vi.PropertySet = new PropertySet(BasePropertySet.IdOnly) vi.PropertySet.Add(FolderSchema.DisplayName) vi.PropertySet.Add(FolderSchema.Id) vi.PropertySet.add(FolderSchema.FolderClass) vi.Traversal = FolderTraversal.Deep Trace("The " + clInbox.DisplayName + " has " + clInbox.ChildFolderCount + " child folders."); // Now do something with the folder, such as display each child folder's name and ID. clFoldersFound is a FindFoldersResults clFolder is a Folder(ServiceEWS) sFolder is string clBMimeContent is a MimeContent() nFile is int clMail2 is an EmailMessage(ServiceEWS) bufMsg is Buffer nLen is int sFname is string WHEN EXCEPTION IN WHILE bMoreItems = True clFoldersFound &lt;- ServiceEWS.FindFolders(WellKnownFolderName.Inbox,Scfilt,vi) bMoreItems = clFoldersFound.MoreAvailable IF bMoreItems = True THEN vi.Offset = vi.Offset + ipagesize END nIIter = 0 nIDspCnt = clFoldersFound.Folders.Count FOR ALL it OF clFoldersFound.Folders clFolder.DisplayName = it.displayname sFolder = Upper(clFolder.displayname) SWITCH Left(sFolder,3) CASE "LON", "HOU", "PER", "NEW", "SGP", "RSA", "BRL" Trace(it.DisplayName) clFindresults2 is a 'FindItemsResults&lt;Microsoft.Exchange.WebServices.Data.Item&gt;' clFindresults2 &lt;- ServiceEWS.FindItems(it.id,new ItemView(10)) Trace("ok") //Get Items FOR ALL i OF clFindresults2.Items sFname = "\ est_" + TimeSys() + "\.eml" xs2 is an 'Collection&lt;Microsoft.Exchange.WebServices.Data.PropertyDefinitionBase&gt;' xs2.add(ItemSchema.MimeContent) xs2.add(ItemSchema.TextBody) clMail2 &lt;- EmailMessage.Bind(ServiceEWS,i.id, new PropertySet(BasePropertySet.IdOnly,xs2)) fDelete(SysDir(srMyDocuments) + sFname) nFile = fOpen(SysDir(srMyDocuments) + sFname,foCreateIfNotExist+foUnicode) //Crashes here :( fWrite(nFile,clMail2.MimeContent.content) fClose(nFile) Trace("woop") END OTHER CASE Trace("no match - " + it.DisplayName) END END END DO END</description><ttl>30</ttl><generator>WEBDEV</generator><language>en_US</language><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp</link><title>EWS extract mail to .eml</title><managingEditor>moderateur@pcsoft.fr (El moderador)</managingEditor><webMaster>webmaster@pcsoft.fr (El webmaster)</webMaster><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60786/read.awp</comments><pubDate>8 May 2017 15:46:00 Z</pubDate><description>Hi Peter,&#13;
&#13;
Thanks for the info. I try to avoid .NET as much as possible but this API is too good to miss! :)&#13;
&#13;
So many possib…</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60786/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60786/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60772/read.awp</comments><pubDate>8 May 2017 11:19:00 Z</pubDate><description>Hi Bosh,&#13;
&#13;
Just FYI:&#13;
In .Net (C#) any reference type derives from the base Object Class which has the ToString method.&#13;
So, al…</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60772/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60772/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60771/read.awp</comments><pubDate>8 May 2017 09:42:00 Z</pubDate><description>Hi Jose,&#13;
&#13;
Thanks for your help. It works perfectly!&#13;
Sorry, I didn't see that method in the documentation :0&#13;
&#13;
Cheers&#13;
&#13;
Bosh</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60771/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60771/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60770/read.awp</comments><pubDate>8 May 2017 01:02:00 Z</pubDate><description>So after all you had a compilation error by windev saying that mimecontent is not a string...&#13;
&#13;
Had you say it first, and would…</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60770/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60770/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60765/read.awp</comments><pubDate>7 May 2017 14:24:00 Z</pubDate><description>Hi Tor-Bjarne&#13;
&#13;
Thanks for the suggestion but the problem is much simpler. The Windev editor itself is complaining about the sy…</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60765/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60765/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60764/read.awp</comments><pubDate>7 May 2017 11:08:00 Z</pubDate><description>Hi,&#13;
&#13;
Perhaps you should try sFname = ".\ est_" + TimeSys() + "\.eml" as you now are trying to save a .eml file in the \ est_" …</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60764/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60764/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60749/read.awp</comments><pubDate>5 May 2017 18:49:00 Z</pubDate><description>Hi Fabrice&#13;
&#13;
I have tried&#13;
&#13;
sFname = "\ est_" + TimeSys() + "\.eml"&#13;
fSaveText(SysDir(srMyDocuments) + sFname,clMail2.MimeCont…</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60749/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60749/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60746/read.awp</comments><pubDate>5 May 2017 15:36:00 Z</pubDate><description>Hi&#13;
&#13;
so what is the incorrect syntax you are using?&#13;
&#13;
Best regards</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60746/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60746/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60732/read.awp</comments><pubDate>4 May 2017 15:31:00 Z</pubDate><description>Hi Fabrice, I tried fsavetext and it reports 'no compatible syntax' :(</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60732/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60732/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60730/read.awp</comments><pubDate>4 May 2017 15:21:00 Z</pubDate><description>Hi Fabrice&#13;
&#13;
Actually the code I posted is slightly incorrect. I am loading each message in the last loop with clmail2.Load().&#13;…</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60730/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60730/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item><item><author>guest</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60728/read.awp</comments><pubDate>4 May 2017 14:41:00 Z</pubDate><description>Hi&#13;
&#13;
what is the error message ?&#13;
Why not do a fsauvetext?&#13;
&#13;
Best regards</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60728/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml-60728/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/60721-ews-extract-mail-eml/read.awp">EWS extract mail to .eml</source><title>Re: EWS extract mail to .eml</title></item></channel></rss>
