Combining 2 scripts together. Mail merge and stationery

Hi All,

Below is a great script which allows the creation of multiple emails (in Mail) from a name/email list .txt file.

What I would like to achieve though is to add a Stationery Category to the email upon creation.

I found this topic http://macscripter.net/viewtopic.php?id=36657

But im having trouble tying it all together.

Any help appreciated. Thanks

(* Copyright 2008 Gianugo Rabellino - http://boldlyopen.com 
   This snippet is licensed under the Apache License version 2.0
   see http://www.apache.org/licenses/LICENSE-2.0.html 
  Modifications by Graham Kirby http://boldlyopen.com/2008/08/26/poor-mans-mail-merge-in-apple-mail/ *)

tell application "Mail" to set allAccounts to name of every account
choose from list allAccounts with title "Choose the Mail account to use..."
set theAccount to result as string

tell application "Mail" to set allSignatures to name of every signature
choose from list allSignatures with title "Choose the signature to use."
set theSignatureName to result as string

set subjectDialog to display dialog ¬
	"Enter the subject of the email to send" default answer "no subject"
set theSubject to text returned of subjectDialog

set sendOrPreview to the button returned of ¬
	(display dialog ¬
		"Send the messages right away or preview and send manually?" with title ¬
		"Send or Preview?" with icon caution ¬
		buttons {"Preview", "Send"} ¬
		default button 1)

set theText to (choose file with prompt "Pick a text file containing the email text")

set messageBody to read theText

tell application "Finder"
	set addresses to paragraphs of ¬
		(read (choose file with prompt "Pick a text file containing email addresses, one by line"))
end tell

set AppleScript's text item delimiters to space

tell application "Mail"
	activate
	set activeAccount to account theAccount
	repeat with i from 1 to (the length of addresses)
		set target to item i of addresses
		set targetWords to every text item of target
		
		if (the length of targetWords) > 1 then
			set forename to first word of target
			set theContent to "Dear " & forename & return & return & messageBody
		else
			set theContent to messageBody
		end if
		
		
		set newMessage to make new outgoing message ¬
			with properties {subject:theSubject, content:theContent}
		
		set message signature of newMessage to signature theSignatureName of application "Mail"
		
		tell newMessage
			set sender to ¬
				((full name of activeAccount & " < " & email addresses of activeAccount as string) & " >")
			
			make new to recipient at end of to recipients ¬
				with properties {address:(a reference to target)}
			set visible to true
		end tell
		
		tell application "System Events"
			tell application process "Mail"
				set frontmost to true
			end tell
			keystroke "T" using {command down, shift down}
		end tell
		
		if sendOrPreview is equal to "Send" then
			send newMessage
		end if
	end repeat
end tell

Browser: Safari 536.5
Operating System: Mac OS X (10.7)

Hi All,

I have tried to get my problem above working, but am tearing my hair out over it.

If any experts out there can help (or at least let me know if it’s not possible) I would be muh aprreciated.

Thank you! :slight_smile: