Re: Creating complex HTML messages in mail via AppleScript
Re: Creating complex HTML messages in mail via AppleScript
- Subject: Re: Creating complex HTML messages in mail via AppleScript
- From: Axel Luttgens <email@hidden>
- Date: Sun, 23 Sep 2007 18:31:35 +0200
On 14/09/07 19:53, John C. Welch wrote:
[...]
I just need to dump the raw source into a new outgoing message as an HTML
email, not just the text of the source, but I'll be buggered if I can do
this in Mail.
Hello John,
Given that "html content" property of an outgoing message, one would be
tempted to believe that you aren't asking for the moon.
Now, it is a well-known fact that Mail is sooo surprising...
As a result, the script below goes through another path.
But, due to my congenital inability to grasp Mail's scripting model, it
obviously requires some improvements. :-(
Someone?
Axel
-- Define these ones as needed.
set MsgFrom to "email@hidden"
set MsgTo to "email@hidden"
set MsgSubject to "Some HTML Data"
set MsgData to "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
</head>
<body>
Message's <b>nice</b> contents
</body>
</html>
"
-- Create a fake Mail mbox containing a single message built with above
data.
set MBoxName to "Tmp" & (random number from 900000 to 999999)
set MBoxPath to "/private/var/tmp/" & MBoxName & ".mbox"
set MessagesPath to MBoxPath & "/Messages"
set EmlxPath to MessagesPath & "/999999.emlx"
do shell script "mkdir -p " & MessagesPath & "; touch " & EmlxPath
write "999999
Mime-Version: 1.0
Content-Type: text/html
From: " & MsgFrom & "
To: " & MsgTo & "
Subject: " & MsgSubject & "
" & MsgData to POSIX file EmlxPath
-- Import that mbox and "send" its message.
tell application "Mail"
import Mail mailbox at MBoxPath
try
set ImportedMB to first item of (every mailbox whose name is
MBoxName)
on error
display dialog "Sorry, import seems to have failed."
-- Delete the fake mbox.
do shell script "rm -r " & MBoxPath
return
end try
-- A workaround, since I couldn't make the "send" command work.
move (first message of ImportedMB) to mailbox "Outbox"
-- Don't know how to get rid of the "enclosing folder"...
delete ImportedMB
end tell
-- Delete the fake mbox.
do shell script "rm -r " & MBoxPath
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden