How can I put all of the previous recipients in a new email?

The script that I am working on should take all of the previous information and put it into a new email with all of the previous recipients. I am having a hard time getting all of the previous recipients put into the cc header or to header of the new email. Any assistance would be greatly appreciated.

tell application "System Events"
	activate
	set myMailAccounts to {"@ Action Support", "@ Archive", "@ Read Review", "@ Waiting For"}
	choose from list myMailAccounts with title "Move Message(s)" with prompt "Choose Mailbox?" default items {"@ Archive"}
	set selectedMailBox to result as string
end tell

if selectedMailBox is "@ Archive" then tell application "Mail"
	set s to selection
	repeat with eachMessage in s
		move eachMessage to mailbox "@ Archive" --of account "On My Mac"
	end repeat
end tell

if selectedMailBox is "@ Action Support" then tell application "Mail"
	set s to selection
	set theRTM to item 1 of s
	
	set theMessage to theRTM
	set orgSubject to subject of theMessage
	set orgMessage to content of theMessage
	set message_url to "message://%3c" & (the message id of theMessage) & "%3e"
	set theMessage to make new outgoing message with properties {visible:true, subject:orgSubject, content:"List:" & return & "Priority:" & return & "Due:" & return & "Repeat:" & return & "Estimate:" & return & "Tags:" & return & "Url: " & return & "---" & return & message_url & return & "---" & return & orgMessage & return & "-end-"}
	
	
	tell theMessage
		make new to recipient at end of to recipients with properties {name:"Next Action", address:"xxxxx@xxxxx.com"}
	end tell
	
	repeat with eachMessage in s
		move eachMessage to mailbox "@ Action Support" --of account "On My Mac"
	end repeat
end tell

if selectedMailBox is "@ Waiting For" then tell application "Mail"
	set theSelection to selection
	set theMessage to item 1 of theSelection
	set theRecipients to to recipients of theMessage
	set cctheRecipients to cc recipients of theMessage
	set theFrom to sender of theMessage
end tell
tell application "Mail"
	set s to selection
	set theRTM to item 1 of s
	set theMessage to theRTM
	set orgSubject to subject of theMessage
	set orgMessage to content of theMessage
	set message_url to "message://%3c" & (the message id of theMessage) & "%3e"
	set theMessage to make new outgoing message with properties {visible:true, subject:"RE: " & orgSubject, content:"List: Waiting" & return & "Priority:" & return & "---" & return & "---" & return & message_url & return & return & orgMessage & return & "-end-"}
	
	
	tell theMessage
		
		make new to recipient at end of to recipients with properties {name:theFrom, address:theFrom}
		(*
		set theRecipients to to recipients of theMessage
		repeat with i from 1 to count to recipients of theMessage
			properties of item i of theRecipients
			make new to recipient at end of cc recipients with properties {name:theRecipients, address:theRecipients}
			
			
		end repeat
		*)
		make new to recipient at end of bcc recipients with properties {name:"Next Action", address:"xxxxxxxx@xxxxx.com"}
	end tell
	set s to selection
	repeat with eachMessage in s
		move eachMessage to mailbox "@ Waiting For" --of account "On My Mac"
	end repeat
end tell

if selectedMailBox is "@ Read Review" then tell application "Mail"
	
	set s to selection
	repeat with eachMessage in s
		move eachMessage to mailbox "@ Read Review" --of account "On My Mac"
	end repeat
end tell

tell application "Mail"
	activate
end tell

I don’t understand what you are trying to do, don’t worry someone else will. :slight_smile:

I just want to say that you don’t have to use

tell app "System events"

to use a display dialog
If you are concerned about the display dialog being not activated then you can use

tell me to activate
choose from list.........

Perhaps something like this

tell application "Mail"
    set oldMessage to message 1 of mailbox "inStaffReportFolder" of mailbox "z09WEFrecords"
    
    set newMessage to make new outgoing message
    set visible of newMessage to true
    tell newMessage
        
        repeat with aRecipient in to recipients of oldMessage
            set aAddress to address of aRecipient
            make new to recipient at end of to recipients with properties {address:aAddress}
        end repeat
        
        repeat with aRecipient in cc recipients of oldMessage
            set aAddress to address of aRecipient
            make new to recipient at end of cc recipients with properties {address:aAddress}
        end repeat
        
        set subject to subject of oldMessage
        set content to content of oldMessage
        
    end tell
end tell

I don’t understand why I have to introduce the aAddress variable, but if I use

make new to recipient at end of cc recipients with properties {address:(address of aRecipient)}

it errors.

AppleScript often ignores politely the absence of the keyword get, but not always :wink:


    make new to recipient at end of cc recipients with properties {address:(get address of aRecipient)}

Thanks, Stefan.

Thanks for the quick responses (amazing and great community), I would have responded earlier, but I was out only with my BB.

@Chris - this is script is a compilation of hacks and my years of get-by with Applescript
@ mikerickson - I tried the script , and it opens up a new message, but I do not see any recipients at all.

Andre

You would need to change the ‘path’ to oldMessage to match some existing message in your Mail mailboxes.

mikerickson,
Thanks again for explaining. I added this line so that I could have more of a dynamic deal ( there is really no set path that I use)

tell application "Mail"
	set s to selection
	set theMessage to item 1 of s
	set theMailbox to mailbox of theMessage
	set theAccount to account of mailbox of theMessage
	-- set oldMessage to theMessage of theMailbox of theAccount
	set newMessage to make new outgoing message
	set visible of newMessage to true
	tell newMessage
		
		repeat with aRecipient in to recipients of theMessage
			set aAddress to address of aRecipient
			make new to recipient at end of to recipients with properties {address:aAddress}
		end repeat
		
		repeat with aRecipient in cc recipients of theMessage
			set aAddress to address of aRecipient
			make new to recipient at end of cc recipients with properties {address:aAddress}
		end repeat
		
		set subject to subject of theMessage
		set content to content of theMessage
		
	end tell
end tell

And here is the final. It helps me with RTM a great deal and I really appreciate the help.

tell application "System Events"
	activate
	set myMailAccounts to {"@ Action Support", "@ Archive", "@ Read Review", "@ Waiting For"}
	choose from list myMailAccounts with title "Move Message(s)" with prompt "Choose Mailbox?" default items {"@ Archive"}
	set selectedMailBox to result as string
end tell

if selectedMailBox is "@ Archive" then tell application "Mail"
	set s to selection
	repeat with eachMessage in s
		move eachMessage to mailbox "@ Archive" --of account "On My Mac"
	end repeat
end tell

if selectedMailBox is "@ Action Support" then tell application "Mail"
	set s to selection
	set theRTM to item 1 of s
	
	set theMessage to theRTM
	set orgSubject to subject of theMessage
	set orgMessage to content of theMessage
	set message_url to "message://%3c" & (the message id of theMessage) & "%3e"
	set theMessage to make new outgoing message with properties {visible:true, subject:orgSubject, content:"List:" & return & "Priority:" & return & "Due:" & return & "Repeat:" & return & "Estimate:" & return & "Tags:" & return & "Url: " & return & "---" & return & message_url & return & "---" & return & orgMessage & return & "-end-"}
	
	
	tell theMessage
		make new to recipient at end of to recipients with properties {name:"Next Action", address:"xxx.com"}
	end tell
	
	repeat with eachMessage in s
		move eachMessage to mailbox "@ Action Support" --of account "On My Mac"
	end repeat
end tell

if selectedMailBox is "@ Waiting For" then tell application "Mail"
	set s to selection
	set theMessage to item 1 of s
	set theMailbox to mailbox of theMessage
	set theAccount to account of mailbox of theMessage
	set theFrom to sender of theMessage
	set message_url to "message://%3c" & (the message id of theMessage) & "%3e"
	
	-- set oldMessage to theMessage of theMailbox of theAccount
	set newMessage to make new outgoing message
	set visible of newMessage to true
	tell newMessage
		make new to recipient at end of to recipients with properties {name:theFrom, address:theFrom}
		repeat with aRecipient in to recipients of theMessage
			set aAddress to address of aRecipient
			make new to recipient at end of to recipients with properties {address:aAddress}
		end repeat
		
		repeat with aRecipient in cc recipients of theMessage
			set aAddress to address of aRecipient
			make new to recipient at end of cc recipients with properties {address:aAddress}
		end repeat
		
		set subject to "RE: " & subject of theMessage
		set content to "List: Waiting" & return & "Priority:" & return & "---" & return & "---" & return & message_url & return & return & "-end-" & return & content of theMessage
		
		
		
		make new to recipient at end of bcc recipients with properties {name:"Next Action", address:"xxx.com"}
	end tell
	set s to selection
	repeat with eachMessage in s
		move eachMessage to mailbox "@ Waiting For" --of account "On My Mac"
	end repeat
end tell

if selectedMailBox is "@ Read Review" then tell application "Mail"
	
	set s to selection
	repeat with eachMessage in s
		move eachMessage to mailbox "@ Read Review" --of account "On My Mac"
	end repeat
end tell

tell application "Mail"
	activate
end tell