Hi Bern,
very nice try. It works fine but it doesn't solve the problem. I already have a way to replace the elements of the email (address, body, subject) in the script by putting the script in a variable and then replace the placeholders.
Code that I put in the variable tTheScript:
Code: Select all
tell application "Mail"
set theSubject to "%emailSubject%" -- Subject
set theContent to "%emailBody%" -- Body
set theAddress to "%emailAddress%" -- To
set msg to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
send msg
end tell
Code I use to replace placeholders in the variable:
Code: Select all
replace "%emailAddress%" with theAddress in tTheScript
replace "%emailSubject%" with tehSubject in tTheScript
replace "%emailBody%" with theMessage in tTheScript
Then I do the variable as AppleScript, and it works fine.
Unfortunately I think (not sure if I'm right or not) that those two ways (mine and yours) have the problem that you can't pass a real-word email message because it could contain characters and schemas that can broke the script, for example reserved AppleScript patterns of words, quotes and so on.
So I think that the solution could be to have AppleScript that directly gets the email body text in some way, this should avoid to put the email body text directly in the AppleScript script.
Alternatively you have to parse the text to use as email body text in the way that you are sure that don't broke the script.