• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating complex HTML messages in mail via AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Creating complex HTML messages in mail via AppleScript (From: "John C. Welch" <email@hidden>)

  • Prev by Date: Re: Check if app exists
  • Next by Date: Re: Check if app exists
  • Previous by thread: Re: Creating complex HTML messages in mail via AppleScript
  • Next by thread: Re: Creating complex HTML messages in mail via AppleScript
  • Index(es):
    • Date
    • Thread