Read mail content from exchange 365 account

Hi all

I create some script to read content or attachments from a Mail account thanks to the people in this forum and it will work on almost all accounts. But I can’t get it to work on my exchange account that I also have in Mail. What must I change in this line to get it working for my 365 account :

set MyMailBox to mailbox "INBOX" of account "MyAccount"

Thanks for reading this post

I tried with my Exchange account and it looks like the mailbox names are case-sensitive.

set MyMailBox to mailbox "Inbox" of account "MyAccount"

In my other accounts I must always use INBOX, what do you enter as account name for your Exchange account, Exchange is not working. MacExcel the normal account does work
Screenshot 2024-04-22 at 16.19.53

I suspect the account names may be different for different user? Let me explain how I got it. First, I run the following code to get the list of accounts I have:

tell application "Mail" to get the name of every account

On my computer the result is

{"iCloud", "Exchange"}

So my exchange account is named (surprise!) “Exchange”, but maybe on your computer it has a different name? That would explain why it doesn’t work.
Then I want to know the names of mailboxes I have on the account named “Exchange”. So I run the following code:

tell application "Mail" to get the name of every mailbox of account "Exchange"

The result on my computer is a long list of mailboxes I have:

{"Clutter", "Conversation History", "Journal", "Conflicts", "Local Failures", "Server Failures", "Sync Issues", "Archive", "Tasks", "Notes", "Inbox", "Outbox", "Drafts", "Sent Items", "Deleted Items", "Junk Email"}

So then I can access the mailbox I want:

tell application "Mail" to set MyMailbox to mailbox "Inbox" of account "Exchange"

The name is case-sensitive; if I change “Inbox” to “INBOX”, it no longer works.

Great now I found the problem, My name is also Exchange but it seems that it use the Dutch folder name from the Inbox on my exchange account on my English Macbook, named “Postvak IN”, when I use that it is working. It show on my MacBook in Mail as “Inbox” so I never thought about it that it use the Dutch name. Thanks for your time