Sorry to bring this one up again i'm having a few problems with it.
It appears to get stuck and ends up sending an email to which ever is selected first from the list
Brand_A
Brand_B ---->Selected
Brand_C
Brand_D
Brand_E
Brand_F ---->Selected
Brand_G
Brand_H---->Selected
Brand_J
Brand_K---->Selected
Brand_M
So if the above are selected Brand_B gets the correct email and Brands F, H, K all get the email for Brand_B
This is the code below and at the very bottom is the html of the content page that it references.
tell application "Mail" to quit
--while mail is closed, add in the default Reply-To key in a UserHeaders dictionary
do shell script "defaults write com.apple.mail UserHeaders '{\"Reply-To\" = \"allpeople@work.com\"; }'"
display dialog "Please enter the current week number." default answer ""
set weekNumber to text returned of the result
set brandsToUse to choose from list {"Brand_A", "Brand_B", "Brand_C", "Brand_D", "Brand_E", "Brand_F", "Brand_G", "Brand_H", "Brand_J", "Brand_K", "Brand_M"} with prompt "Choose brands to send out." with multiple selections allowed
-- get the html template
set htmlTemplate to read "Users/matthew/WorkFlow/EMAIL PROJECT/content.html"
considering case
-- this section splits the template text at every XX, then rejoins it using the week number
set htmlTemplate to tid(htmlTemplate, "XX")
set htmlTemplate to tid(htmlTemplate, weekNumber)
end considering
tell application "Mail"
set subjectLine to "Week " & weekNumber & " images"
repeat with thisBrand in brandsToUse
considering case
-- this section adds the brand name, done inside the loop because it's different for each email
-- the 'my' keyword is needed because you're calling a handler from within a tell block
set htmlContent to my tid(htmlTemplate, "*LOGO*")
set htmlContent to my tid(htmlContent, brandsToUse)
end considering
-- create a new message. visible must be false for the 'html content' line to work correctly
set newMessage to makenewoutgoing messagewith properties {subject:subjectLine, visible:false}
tell newMessage
-- create a variable recipient address based on brand name
makenewto recipientat end of to recipientswith properties {address:"All" & thisBrand & "Team@work.com"}
set html content to htmlContent
-- send the email
send
end tell
end repeat
end tell
on tid(input, delim)
-- generic handler for doing text item delimiters
set {oldTID, my text item delimiters} to {my text item delimiters, delim}
if class of input is list then
set output to input as text
else
set output to text items of input
end if
set my text item delimiters to oldTID
return output
end tid
tell application "Mail" to quit
--wait till Mail is closed, then remove the dictionary
delay 3
do shell script "defaults delete com.apple.mail UserHeaders"
tell application "Mail" to activate
delay 5
say "All done."
HTML source of Content.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Sticky</title>
</head>
<body style="background:url(bg_pattern.jpg) 50% 0;margin:0;padding:0">
<div style="background:url(bg_pattern.jpg) 50% 0;height:100%;width:100%;">
<table id="main-table" width="342" cellpadding="0" cellspacing="0" align="center">
<tr>
<td id="body-center" width="342" background="note.jpg" style="line-height:2">
<table cellspacing="0" cellpadding="0" class="spacing-table-for-ie5-and-hotmail">
<tr>
<td width="39" rowspan="2" class="left-gutter-spacing" style="font-size:1px"> </td>
<td width="245" class="top-gutter-spacer" height="47"> </td>
<td width="58" rowspan="2" class="right-gutter-spacing" style="font-size:1px"> </td>
</tr>
<tr>
<td class="content-holder" height="313" align="center" valign="top">
<div class="max-height-wrap">
<div class="body-content" id="body-content" style="line-height:1.3">
<font face="Chalkboard, Marker Felt, Comic Sans, sans-serif" color="#22559c" style="font-size:32px;">
<div contenteditable="false" apple-content-name="body" style="display:block;width:245px;height:253px;overflow:hidden">
<DIV><a href="file:///%5C%5Curanus%5Cdckgen%5CBrands%5CZoom%5CBrand%20-%20Zoom%5CUpload %20Photos%5C2013%5CWeekXX%5C*LOGO*_WKXX_LR">Push to View</a></div></DIV>
</div>
</font>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>