Send mail to mails choosed from list of mails

Hi!

I have this code:


set destinatarios to {"email1@gmail.com", "email2@gmail.com", "email3@gmail.com"}
set direcciones_emails to (choose from list destinatarios with prompt "Elige los destinatarios:" with multiple selections allowed) as list

tell application "Mail"
	set theNewMessage to make new outgoing message with properties {subject:"Subject text", content:"Content text", visible:true}
	tell theNewMessage
		make new to recipient at end of to recipients with properties {address: direcciones_emails}
		send
	end tell
end tell

I need add selected items from list “destinatarios” and put them to address, to send mail to those email directions how i can write it?

Hi,

you have to create each recipient separately


set destinatarios to {"email1@gmail.com", "email2@gmail.com", "email3@gmail.com"}
set direcciones_emails to (choose from list destinatarios with prompt "Elige los destinatarios:" with multiple selections allowed)
if direcciones_emails is false then return
tell application "Mail"
	set theNewMessage to make new outgoing message with properties {subject:"Subject text", content:"Content text", visible:true}
	tell theNewMessage
		repeat with unDestinatario in direcciones_emails
			make new to recipient at end of to recipients with properties {address:unDestinatario}
		end repeat
		send
	end tell
end tell


Seems work perfect!

Can i show names instead emails when i show “Choose from list”? i dont know how asociate a mail direction with a name

Thanks

the easiest way is to use two lists with an index prefix in the list to be displayed


property destinatarios : {"email1@gmail.com", "email2@gmail.com", "email3@gmail.com"}
property nameList : {"1 Name1", "2 Name2", "3 Name3"}

set chosenNames to (choose from list nameList with prompt "Elige los destinatarios:" with multiple selections allowed)
if chosenNames is false then return
tell application "Mail"
	set theNewMessage to make new outgoing message with properties {subject:"Subject text", content:"Content text", visible:true}
	tell theNewMessage
		repeat with aName in chosenNames
			set nameIndex to word 1 of aName as integer
			make new to recipient at end of to recipients with properties {address:item nameIndex of destinatarios}
		end repeat
		send
	end tell
end tell