question

JanneLindh-6191 avatar image
0 Votes"
JanneLindh-6191 asked JanneLindh-6191 commented

How do I read mail on the server, programmatically?

I have a VB program in Visual studio 2019 that reads mail folders to retrieve information like sender to create new contacts. Some folders don’t contain all data on the computer: ‘there are more items in this folder on the server’.

My question is how do I connect to the server to be able to read those mail?



Best regards
Janne

office-exchange-server-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GlenScales-6756 avatar image
0 Votes"
GlenScales-6756 answered

• The text that is retrieved is HTML that is not so easy to analyze.

You can set format you the Body you want returned using the bodyType https://docs.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.bodytype?view=exchange-ews-api

However, I do not know how to do if I want to connect to some special folder.

If its a User Created Folder you need to use FindFolder to search for that folder based on it name eg something like https://www.vbforums.com/showthread.php?729451-Custom-EWS-Class-FindFolders-help



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GlenScales-6756 avatar image
0 Votes"
GlenScales-6756 answered JanneLindh-6191 commented

Depending on the version of Exchange (eg OnPrem, Office365) look at using either EWS (onPrem) https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/get-started-with-ews-managed-api-client-applications or the Graph API for Office365 https://developer.microsoft.com/en-us/graph/get-started

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi.

Since last time I wrote I have now a routine that retrieves messages and converts them into text files. The program handles messages in the Inbox and in this folder’s subfolders deep down. So far so good.

My problem now is that it doesn’t work when the same program reads from the Archive folder or from a folder I have created outside Inbox.

Referring to WellKnownFolderName Enum (Microsoft.Exchange.WebServices.Data) | Microsoft Docs

Fields like Inbox and Outbox work fine. It seems that the Archive isn’t organized in the same way. The ArchiveRoot isn’t a folder but something else??


ArchiveRoot 20 The root of the folder hierarchy in the archive mailbox.

So how do I dig into that structure?

When I comes to finding any folder, I don’t even know if there is a root or a folder as the top-level.

I have tried this one.

MsgFolderRoot 10 The root of the message folder hierarchy.

It returns a list of folders, but I cannot see how it organized. It also includes more than one type of folders. Types like Notes and Contacts that I don’t want to handle.


Using this
ArchiveRoot 20 The root of the folder hierarchy in the archive mailbox.

Throws an error

Microsoft.Exchange.WebServices.Data.ServiceResponseException: 'The specified folder could not be found in the store.'


Can you please help me to continue my struggle with the VB code?


Best regards
Janne

0 Votes 0 ·
JanneLindh-6191 avatar image
0 Votes"
JanneLindh-6191 answered GlenScales-6756 commented

Thank you for the reply.

Most examples I have found until now describes code in c#. Since I am only familiar with VB, I cannot use them.

Do you know where I can find example code in VB?

Best regards
Janne

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

When you say VB do you mean VBA or VB.net, the official documentation samples don't track for either of those but there are plenty of examples others have posted depending on what your trying to do eg Graph or EWS. I would suggest you try and start building something and then post questions around what doesn't work or what you don't understand as with VB it unlikely that you going to find an end to end walk-though type sample so its going to require you skill up a little. Its easy to learn however and there are generally lot of people whiling to help with what ever issue you have.

0 Votes 0 ·
JanneLindh-6191 avatar image
0 Votes"
JanneLindh-6191 answered JanneLindh-6191 commented

Thanks for your advice. I will try a small experiment.

It is VB.net. I have never tried VBA in Visual Studio. Is that possible?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

No the only reason people still use VBA these day is if they are writing an Application with Office eg Excel etc, for VB.net there are plenty of community post eg https://jwcooney.com/2018/08/05/programatically-connecting-to-ms-exchange-using-ews/ etc and similar for the Graph, some of the Graph examples may need a bit of modification to work with never versions of the Graph SDK because of the rate of change also with EWS if your using Office365 you want to make sure you use oAuth rather then basic authentication. But the best approach is just start writing some code and see where you get stuck and ask question around that issue, always make sure you post what ever code you using in the question you ask as that help greatly anybody looking to see where the problem lies.

0 Votes 0 ·

Hi. Thanks to the latest link you gave, I have been able to create code that reads email from server (outlook.com). The tests I have run have provided experience for the future.
• The text that is retrieved is HTML that is not so easy to analyze.
• Login requires using an app password
So far, I have only read from the inbox, but it should probably not be so difficult to read from other standard folders. However, I do not know how to do if I want to connect to some special folder.
Does anyone have a suggestion?

BR
Janne

0 Votes 0 ·