I am trying to get a message by its id from Mail.app using Apple Script. It works if the message is still in the inbox, however I have messages on my local mac with the account name "On my mac" whenever I run this script it gives me an error "Mail got an error: Can’t get account "On My Mac". Number: -1728".
# THIS WORKS
# set MessageID to 375586
# set _mailBox to "INBOX"
# set _account to "TheWilliamson"
# THIS DOESN'T WORK
set MessageID to 11351
set _mailBox to "2001"
set _account to "On My Mac"
tell application "Mail"
try
set mybox to mailbox _mailBox of account _account
# ERROR: Mail got an error: Can’t get account "On My Mac". Number: -1728
on error eStr number eNum
display dialog eStr & " Number: " & eNum buttons {"OK"} default button 1
return
end try
end tell