Searching and Opening an Email - Getting message ID

Below is the code I have so far. The variable theMessage is getting set to a message correctly but I can’t pull the ID.

tell application "Mail"
	make new message viewer with properties {selected mailboxes:{inbox}}
end tell
tell application "Mail"
	activate
	tell account "Gmail"
		tell mailbox "INBOX"
			set theMessage to {first message whose subject is "hey you"}
			
			set theid to the theMessage
			display dialog theMessage as text
			
			tell application "Mail" to open (messages of account "Gmail" of mailbox "INBOX" whose id is theMessage)
			
		end tell
	end tell
	display dialog theMessage as text
end tell

I get the following error:

Help? Thanks in advance!

Hi,

you can’t display an element like message with display dialog,
and if you want to get the id of a message, you have to refer to it


.
set theid to id of theMessage
	display dialog theid as text
.

Hi StefanK,

Thanks for the quick response.

I tried what you suggested and received the following error:

Thoughts?

set theMessage to {first message whose subject is "hey you"}

this line coerces the first message to a list, which is certainly not indended


 set theMessage to first message whose subject is "hey you"

Always the smallest things, no?

Thanks so much!! I was racking my brain on this one.

I read just the error message :wink: