make new mailbox in exchange account

The following script works for all types of accounts (IMAP, POP, Exchange 2007, Exchange IMAP) in Mail app without any errors

tell account "accountName" to make new mailbox with properties {name:"Mailbox1"}

However, for Exchange 2007 account, the mailbox is not syncronized with the exchange server, so the messages moved there (and the mailbox itself!) do not appear in other email clients - basically exchange server did not see that mailbox. (by the way, messages moved to that folder from the application UI, are visible, while messages moved using script, are not visible - only message counter is increased)

if I create it from menu, Mailbox->New Mailbox, Mail application itself, has no issues with the mailbox, but mailbox, created using script is not syncronized properly.

Is there a way to make this work (maybe, specifying extra property) or any other way?
except maybe ui automation is not an option for me.

Reviving this old thread as I’m looking to do the same thing — create a Mailbox in an M365 account using scripting. But so far I’ve hit this brick wall when trying to do it with Mail.app (and different but similar walls when trying to script MailMate or Outlook).

Anybody have this working?

tell application "Microsoft Outlook" --Outlook version 16.78.2 (scriptable)
	tell exchange account 1
		set newOutlookFolder to make new mail folder at end
	end tell
end tell

Tags and top posting corrected by NG. (See Markdown reference here.)

Thanks, but this produces the following error:

Script Error
Microsoft Outlook got an error: Can’t get exchange account 1. Invalid Index.

There is, of course, an M365 exchange account (more than one actually).

Are you sure it’s a scriptable Outlook version and an actual Exchange account? (If so, I don’t understand why “Exchange account 1” wouldn’t be valid.) You could try referring to it by name as opposed to “exchange account 1”.

It’s Outlook version 16.78.2 (23102103).

If I sub in this line:
tell exchange account "[my email address]"

I get an error:

Microsoft Outlook got an error: Can’t get exchange account "[my email address]". number -1728 from exchange account “[my email address]”

tell app Outlook to get all accounts

and look at the output to see what accounts are there and how they are identified

tell application "Microsoft Outlook" to get accounts

results in:

error “Microsoft Outlook got an error: Can’t get every account.” number -1728 from every account

(similar errors occur if I try getting account 1 or account 0 or account 2 or first account)

This works for me.
In Outlook scripting, mailboxes are called “mail folders”
This will only work if Outlook is not in “New Outlook” mode.
Also you didn’t mention what version of Outlook you were using?

tell application "Microsoft Outlook"
	set myAccounts to exchange accounts
	set myAccount to item 1 of myAccounts
	tell myAccount
		set mailFolderNames to name of mail folders
		if "Mailbox1" is not in mailFolderNames then
			make new mail folder with properties {name:"Mailbox1"}
		end if
	end tell
end tell
1 Like