0

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
Joseph Williamson
  • 771
  • 1
  • 6
  • 18

1 Answers1

0

The sub "folders" of the "on my Mac" are not accounts, but they are mailbox. Therefore you can get the mailbox using

Set MyMailbox to mailbox of MyMessage --> string with name of the mailbox

Also don't confuse a message and a message ID. the message ID is just a property of your message. fyi, and to make it simple, accounts are the different address emails you have.

pbell
  • 2,965
  • 1
  • 16
  • 13
  • Thank you very much for your fast reply. The problem is I don't have a message, my end goal here is actually to get a message from the "message ID", do you know how I might do that if all I have are: message ID and its mailbox – Joseph Williamson Sep 02 '18 at 13:57
  • You need to get first "every message whose ID is xxx", which gives you a list of 1 item. Get item 1 of that list and you're there with your message – pbell Sep 02 '18 at 14:10