You can find a message’s id with:
tell application "Mail" to get id of first item of (get selection)
However, this script will throw an error.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with aMessage in theMessages
try
set xxx to id of aMessage
display dialog xxx buttons {"Cancel", "OK"} default button "OK"
on error errMsg number errNum
tell me
activate
display alert errMsg & return & return & "Error number" & errNum buttons "Cancel"
end tell
end try
end repeat
end tell
end perform mail action with messages
end using terms from
When is a message assigned its id?
You can replace
set xxx to id of aMessage
with
set xxx to message id of aMessage
and the script will perform as expected.
Is there a workaround to getting the id of an incoming message? If not, are there any unforeseen problems of identifying messages with message id ?