Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

automate sending of emails with a link

At the end of each week I need to mail out a link. This link is a link to folder on a windows network.


Its one of those tasks that I have made a little quicker by making a template in mail.app. However I have to go in and amend that link each week so that it points to the right location. This is tedious still and as a result human mistakes can still be made.


This is my process at the moment

In mail app I select a templates

User uploaded file

Then I select send again or use the keyboard short

User uploaded file

the subject then needs to be amended and I replace the XX with the week number.

then I select the link ctrl click and select edit link

User uploaded file

Again both of the XX get replaced with the week number.

once complete I then hit send.

Then move onto the next brand.

I'm wondering if this could be applescripted?

The first option would be week number

then this is slightly more involved but some kind of selection box to select which brands to recieve the email?

I've looked up a number of scripts and link/html mail seams to be very awkward.

Hopefully I have covered everything that needs to be listed

Matt

iMac, Mac OS X (10.6.8)

Posted on May 29, 2012 6:13 AM

Reply
19 replies

Oct 3, 2012 4:01 AM in response to MattJayC

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>

Oct 3, 2012 8:34 AM in response to MattJayC

Hi,


MattJayC wrote:

It appears to get stuck and ends up sending an email to which ever is selected first from the list


So if the above are selected Brand_B gets the correct email and Brands F, H, K all get the email for Brand_B



sethtmlContenttomytid(htmlContent,brandsToUse) -- brandsToUse is the full list



This is because you use the brandsToUse list instead of an item from this list.


Here is the corrected part :

-----------------------

repeatwiththisBrandinbrandsToUse

consideringcase

-- 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*")

sethtmlContenttomytid(htmlContent, thisBrandaslist) -- thisBrand is an item in the full list

endconsidering

automate sending of emails with a link

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.