1

Using the AppleScript below I am unable to open the message ID. This same message ID is in a note in my Reminders app and clicking on the link works correctly there.

set emailID to "message://<DB43DAF1-7B87-4DE5-99DB-EC11CB0F6FF7@gmail.com>"

tell application "Mail"
    open location emailID
end tell

I get the pop-up error

The operation couldn't be completed.

(MCMailErrorDomain error 1030.)

Mail was unable to open the URL "(null)".

I've researched that error code but the answers don't seem applicable. Also, when removing the word "location" from my AppleScript, Mail will open but with a blank new email.

Any help getting this script to actually open the email with that ID would be greatly appreciated.

1

Mail is not smart enough to just tell it to open a document by just its message id in the manner you're trying to do it. You need to tell Mail where to look for it, as in what mailbox it's in.

The following example worked for me when MessageID was set to one in my Inbox using its proper message id however in this example I'm using the message id shown in your OP.

set MessageID to "DB43DAF1-7B87-4DE5-99DB-EC11CB0F6FF7@gmail.com"

tell application "Mail"
    activate
    open (first message of inbox whose message id = MessageID)
end tell

Note that the example code above is limited in that it doesn't gracefully trap an error, so the example code below adds a try statement with an error statement to handle an error gracefully.

set MessageID to "DB43DAF1-7B87-4DE5-99DB-EC11CB0F6FF7@gmail.com"

tell application "Mail"
    activate
    try
        open (first message of inbox whose message id = MessageID)
    on error eStr number eNum
        display dialog eStr & " Number: " & eNum buttons {"OK"} default button 1
        return
    end try
end tell
  • Muchas gracias. These emails will be in my Sent box, so I simply changed "inbox" to "sent mailbox" and we're good. I can't thank you enough. Saved me quite a bit of time. – El Tigre Nov 10 '16 at 18:27
1
set emailID to "message://<DB43DAF1-7B87-4DE5-99DB-EC11CB0F6FF7@gmail.com>"

tell application "Mail"
    open location emailID
end tell

open location isn't a command in the Mail AppleScript dictionary. Your script is trying to use open on the variable "location". Since no variable named "location" exists, you're calling open on a NULL variable, hence the error message.

set emailID to "message://<DB43DAF1-7B87-4DE5-99DB-EC11CB0F6FF7@gmail.com>"

tell application "Mail"
    open emailID
end tell

open is in the Mail AppleScript dictionary, but it takes a file or list of files as a parameter, so a message:// URL doesn't work with it.

This is what you actually want:

set emailID to "message://<DB43DAF1-7B87-4DE5-99DB-EC11CB0F6FF7@gmail.com>"
open location emailID

tell application "Mail"
    activate
end tell

open location called outside of any tell application will open any URL with whatever application is assigned to the URL scheme. Mail is assigned to message:// so it will work as expected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .