NAV 2013 dotnet Exchange Web Services (EWS)

madsmorremadsmorre 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,

Answers

  • xStepaxStepa Member Posts: 106
    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
    xStepa
  • madsmorremadsmorre Member Posts: 40
    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)?
  • madsmorremadsmorre Member Posts: 40
    edited 2020-05-11
    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));
Sign In or Register to comment.