Mail - delete mailbox

Sonoma 14.4.1 (23E224) SD 8.0.7

I’m trying to fix an issue I’ve ignored for some time, ie deleting a mailbox. I’ve had to do that because when I move a mailbox to another mailfolder I create a new mailbox in the (usually existing) mailfolder, move all the messages, and then try to delete the former mailbox.
'tell application “Mail”
set mailBoxName to “BPIC Building Products Leaders Forum”
set mailFolder to “bsAC”
if exists (mailbox mailBoxName of mailbox mailFolder) then
set boxExists to true
try
set mbxContainer to (mailFolder & “/” & mailBoxName) as string
delete mailbox mailBoxName of mailbox mailFolder
# delete mailbox mbxContainer alternate!
on error
display alert “Moved emails, but cannot delete mailbox”
end try
end if
end tell

1 Like

Hello @jrmitchell

I faced the same issue because my AppleScript mail box did not reference correctly. It may be that this is the same reason for your problem. You should update the script.

I hope this will helpful for you :slightly_smiling_face:

Hi @Helen (apologies for delay)
what exactly would be an “update”? I did recompile (Sonoma, SD8) from the original version (originally dating back to 2012!)

Hello @jrmitchell

Now let’s work on fixing the AppleScript connection to the mailbox.
Make sure the mailbox provided by the mailbox mail box name of the mailbox mail folder is the correct one.
This will fix the deletion problem. Update the script; if necessary, to include the right path to mailbox mailBoxName inside the mailbox mail folder.
I hope this is useful. :+1: