Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
12
Erster Beitrag:
vor 5 Monaten, 2 Wochen
Letzter Beitrag:
vor 5 Monaten, 2 Wochen
Beteiligte Autoren:
bosher, Fabrice Harari, Peter Holemans, Jose Antonio Garrido, Tor-Bjarne, Bosher

EWS extract mail to .eml

Startbeitrag von Bosher am 04.05.2017 10:19

Hi guys.

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)

I can log in just fine, list folder contents, load individual messages, save attachments etc. All good.
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.

Here is my code (Most of which works great), hope fully someone will find this useful
The bit that doesn't work is the saving of the mimecontent near the end.

If anyone has done this successfully, I'd be delighted if you could share

Cheers, Bosh

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

Antworten:

Hi

what is the error message ?
Why not do a fsauvetext?

Best regards

von Fabrice Harari - am 04.05.2017 12:41
Hi Fabrice

Actually the code I posted is slightly incorrect. I am loading each message in the last loop with clmail2.Load().

I am using the .Net assembly Microsoft.Exchange.Webservices so I am receiving no error when I call errorinfo(errfulldetails)

:(

von bosher - am 04.05.2017 13:21
Hi Fabrice, I tried fsavetext and it reports 'no compatible syntax' :(

von bosher - am 04.05.2017 13:31
Hi

so what is the incorrect syntax you are using?

Best regards

von Fabrice Harari - am 05.05.2017 13:36
Hi Fabrice

I have tried

sFname = "\test_" + TimeSys() + "\.eml"
fSaveText(SysDir(srMyDocuments) + sFname,clMail2.MimeContent)

and
sFname = "\test_" + TimeSys() + "\.eml"
fSaveText(SysDir(srMyDocuments) + sFname,clMail2.MimeContent.Content)

Windev not happy with either :0

Cheers

Bob

von bosher - am 05.05.2017 16:49
Hi,

Perhaps you should try sFname = ".\test_" + TimeSys() + ".eml" as you now are trying to save a .eml file in the \test_" + TimeSys() + "\" folder that probably do not exist.

cheers
Tor-Bjarne

von Tor-Bjarne - am 07.05.2017 09:08
Hi Tor-Bjarne

Thanks for the suggestion but the problem is much simpler. The Windev editor itself is complaining about the syntax used (Which is fine). I guess it's clever enough to figure out that the object being saved is not a text object.

My original code mirrors the documented c# code (Still working on it...)
nFile = fOpen(SysDir(srMyDocuments) + sFname,foCreateIfNotExist+foUnicode)
//Crashes here :(
fWrite(nFile,clMail2.MimeContent.content)
fClose(nFile)

Cheers

Bob

von bosher - am 07.05.2017 12:24
So after all you had a compilation error by windev saying that mimecontent is not a string...

Had you say it first, and would save us a lot time.

I checked on google and MimeContent is a class with six methods. One of them being ToString

https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.mimecontent_members(v=exchg.80).aspx

so use MimeContent.ToString

Regards,
José Antonio.

von Jose Antonio Garrido - am 07.05.2017 23:02
Hi Jose,

Thanks for your help. It works perfectly!
Sorry, I didn't see that method in the documentation :0

Cheers

Bosh

von bosher - am 08.05.2017 07:42
Hi Bosh,

Just FYI:
In .Net (C#) any reference type derives from the base Object Class which has the ToString method.
So, all types in .Net have a ToString method (with many different signatures for about any purpose).
https://msdn.microsoft.com/en-us/library/system.object.tostring(v=vs.110)

Cheers,

Peter

von Peter Holemans - am 08.05.2017 09:19
Hi Peter,

Thanks for the info. I try to avoid .NET as much as possible but this API is too good to miss! :)

So many possibilities.

Backup for office365 mail anyone? Easy!
Integrate email into CRM etc...

Thanks for your help guys

Cheers

Bosh

von bosher - am 08.05.2017 13:46
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.