NAV 2013 dotnet Exchange Web Services (EWS)

madsmorre
Member Posts: 40
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,
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
-
Hi, it's not difficult to transform FOREACH:
FOREACH Mail IN Mails DO ...
into:FOR i := 1 TO Mails.Count DO BEGIN Mail := Mails.Item(i); ... END;
(this is just an example, don't know this library)Regards
xStepa0 -
Thanks for answering 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)?0 -
This is where I am at the moment
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));0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions