Hi
I'm new to using dotnet types to make development, so i'm trying to see/learn from examples which i'm finding. In this case I can't find anything that seems to be useable and therefor I'm asking the forum.
My task is to (via NAV code - in NAV 2013)
1. loop through an Exchange mailbox folder
2. extract the attachements (only certain types - "filters")
3. save these to a folder
4. move the mail to another (sub)folder in the same User account.
So far I have found out how to access the mailfolder (only wellknownfolder - "Inbox"). From this I can take out information on how many mails (items) there are in the folder and how many unread - from the "Folder.TotalCount"/"Folder.Unread"
I have also managed to create an EmailMessage and to send it from the EWS (just to test)
I have found an example on looping through mails to syncronize the folder to NAV, but this is from a NAV 2016 where FOREACH is used. This command is not a part of the functionality in NAV 2013.
I need to learn how to use a loop with the dotnet types and to use this to loop through the mails in the folder. And from there to sve the attachements (if any)
As I can't find any examples on how to move on, I'm asking if anyone could either guide me to any of these or show some quick tricks.
Thx,
0
Answers
into:
(this is just an example, don't know this library)
xStepa
There should be a library then for "Mails" - what could this be.
For Mail I think I should use this library: Microsoft.Exchange.WebServices.Data.EmailMessage.'Microsoft.Exchange.WebServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
To get this straight:
1. I got the folder (Inbox) in the chosen Exchange Account. And I have access to it.
2. I should put this into a "Mails"- a kind of box to hold all the items in the folder
3. Then loop through the "Mails" and for every circle I would put the info into my Variable EmailMessage. And then I have access to the content of the message (from, to, subject, attachements etc)?
ExchangeService := ExchangeService.ExchangeService();
ExchangeService.UseDefaultCredentials;
//Delegate permissions
//GetCredentials(WebCredentials);
//ExchangeService.Credentials := WebCredentials;
ExchangeService.Url := Uri.Uri(GLSetup."EWS Url");
Mailbox := Mailbox.Mailbox(MailboxName);
FolderId := FolderId.FolderId(WellKnownFolderName.Inbox,Mailbox);
Folder := Folder.Bind(ExchangeService,FolderId);
UnreadEmails := Folder.UnreadCount;
TotalEmails := Folder.TotalCount;
MESSAGE('Unread: '+FORMAT(UnreadEmails)+', Total: '+FORMAT(TotalEmails));