New Mail Message

Is it possible to create a new mail message to be sent to a contact group. I currently have the following line of code in my Applescript and it works as expected.

make new to recipient with properties {address:"recipientemail@gmail.com"}

In contacts I have a group called “Family”. How can I use Applescript to send mail to the group without spelling out every address? I have tried every possible iteration I can think of, but I always get a scripting error. Is it even possible to do this?

I generally avoid even looking at Mail scripting but for whatever reason…

Try this to add the contact group ‘tsn’:

tell application "Mail"
	set ts to "potentially a subject"
	set tc to "read this text content"
	set tAddressGroup to "tsn"
	
	set outMess to make new outgoing message with properties {subject:ts, content:tc}
	tell outMess to make new recipient at end of to recipients with properties {address:tAddressGroup}
	
end tell

Note the convoluted method of expressing a recipient. FWIW, one of the things I loathe about Mail is that it is difficult (at least for me) to determine how to reference anything. I found the syntax here:

https://gist.github.com/youandhubris/9e292822e3db8f91df93234db092906e

Quirkily, the newly created email will just contain the group’s name as text and will not expand it or format it visibly. However, once you do anything (e.g. save as draft, tab into the next field) it will deposit the message into the drafts folder with the email addresses of the group members. There might be a way to get it to do this automatically but I think I’ve reached my Mail limit for one year. This works with Mail 10.3 (Sierra).