Apple Mail - how to get the recipient of current mail

Hi forum,

I need to find out some information about the current eMail (selected in message viewer or the message of the frontmost window) in Apple Mail but I couldn’t figure out why this doesn’t work (tried with Mail Version 2.0.5 (746/746.2)):


tell application "Mail"
	set theSelection to selection
	if ((count of theSelection) = 1) then
		tell item 1 of theSelection
			set theSubject to subject                        -- works
			set theSender to sender                          -- works 
			set theRecipient to address of recipient     -- does not work
			set theID to id                                       -- works
		end tell
		set theRecipient to address of recipient of message id theID -- does not work
	else
		get selected mailboxes of message viewer 1
	end if
end tell

Anybody an idea, why - or how to solve this? Many thanks for your help in advance.

Dominik

I think the recipients are a list even if there’s only one. I don’t use Mail, but something like this:

set receivers to address of to recipient of eachMessage as list

many thanks - but unfortunately this does not solve the problem …

Dominik:

Adam was pretty close. The recipient class is a list, so you need to ask for the name or address of the first recipient to get the primary recipient:


tell application "Mail"
	set theSelection to selection
	if ((count of theSelection) = 1) then
		tell item 1 of theSelection
			set theSubject to subject -- works
			set theSender to sender -- works 
			set theRecipient to address of first recipient -- Now it works.
			set theID to id -- works
		end tell
	else
		get selected mailboxes of message viewer 1
	end if
end tell

I deleted your other line, trying to get the address via the ID, since it is no longer necessary.

Many thanks for your help, Jacques, Craig & Adam :slight_smile: