Sending Complex HTML emails with MAIL

Hi,
Does anyone have a script to send complex html emails with Mail?

I have a script that works with Outlook. Could someone guide me in how to change it to work with MAIL. (I don't know anything about writing scripts.)

Martha

Posted on Nov 6, 2004 12:40 PM

Reply
48 replies

Nov 6, 2004 1:34 PM in response to Martha

Martha,

the following script works for me - you will have to keep in mind that linked pictures, links, ... will have to be accessible from the receiving mail client (i.e., be located somewhere on a server) since they will not be embedded in the message itself...

i Andreas

P.S. Since this board seems to add line breaks, you will have to massage the script a little - the error message in the Script Editor should make it obvious where you will have to remove breaks...

tell application "Mail"
try
set theSourceMsg to outgoing message 1
set keepGoing to true
on error
set keepGoing to false
display dialog "Please create a new message containing the recipients and subject before running this script." with icon 1 buttons "OK" default button 1
end try
if keepGoing and ((count of to recipients of theSourceMsg) + (count of cc recipients of theSourceMsg) + (count of bcc recipients of theSourceMsg) = 0) then
display dialog "Please enter the recipients before running this script." with icon 1 buttons "OK" default button 1
set keepGoing to false
end if
if keepGoing then
tell application "System Events" to set useSafari to (process "Safari" exists)
if useSafari then tell application "Safari" to set useSafari to (count of (windows whose visible is true and name is not "Downloads")) > 0
if useSafari then
display dialog "Please choose the source for your HTML message" buttons {"Front window in Safari", "Choose FileÂ…"}
set useSafari to button returned of the result = "Front window in Safari"
end if
if not useSafari then
try
set theFileLocation to choose file with prompt "Please choose and HTML file to be sent:"
on error
set keepGoing to false
end try
end if
if keepGoing then
try
set theSender to sender of theSourceMsg
set theSubject to subject of theSourceMsg
set theMsg to make new outgoing message with properties {sender:theSender, subject:theSubject, visible:false}
tell theMsg
repeat with eachRecipient in to recipients of theSourceMsg
set theName to name of eachRecipient
set theAddress to address of eachRecipient
make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
end repeat
repeat with eachRecipient in cc recipients of theSourceMsg
set theName to name of eachRecipient
set theAddress to address of eachRecipient
make new cc recipient at end of cc recipients with properties {name:theName, address:theAddress}
end repeat
repeat with eachRecipient in bcc recipients of theSourceMsg
set theName to name of eachRecipient
set theAddress to address of eachRecipient
make new bcc recipient at end of bcc recipients with properties {name:theName, address:theAddress}
end repeat
if useSafari then
tell application "Safari" to set theHTMLContent to source of document of window 1
else
set theFile to open for access theFileLocation without write permission
set theHTMLContent to read theFile from 1 to (get eof theFile)
close access theFileLocation
end if
set html content to theHTMLContent
end tell
send theMsg
delete theSourceMsg
on error
delete theMsg
display dialog "Failed to generate HTML message." with icon 1 buttons "OK" default button 1
end try
end if
end if
end tell

Nov 6, 2004 5:02 PM in response to Martha

Hi Andreas,
Slight problem when the html email is forwarded. I have an image that is approx 445 pixels x 500 pixels that I sliced to speed downloading.

When I try to forward it (which I am hoping my clients will do), the photo breaks up and goes all over the place. Is this a function of the script or the table I have the image layout in? (I used ImageReady to generate the table for the sliced image.)

Thanks,
Martha

Nov 28, 2004 2:39 PM in response to Martha

Thanks for the script! this worked really well! It was so easy!

Just to clarify for anyone else out there, you just open AppleScript, paste in the above script, and run it.

Also, it will tell you this, but you need to create an email with the recipients and subject line before you run it. You can then either select an html file or the "front window" in Safari, which is great. A note about html emails: You do need to have the images posted on a server and you must make your file references absolute in your html file (each image will have a complete url e.g. www.myserver.com/image1.html).

Dec 22, 2004 12:34 AM in response to Chiuchutrain

Hi - Linda Chiu
Launch Apple Mail
From the Script menu (it's a script symbol) select Open Scripts Folder and place the script in the folder
Again, from the Script menu (it's a script symbol) select Update Scripts Menu
Now your ' Sending Complex HTML' script will be in Apple's Mail -- Script menu

Tom X<center> <table bgcolor="#939330" border="0" cellspacing="0"> <tbody> <tr> <th nowrap="nowrap" valign="top"> <table bgcolor="#7a7a00" border="0" cellspacing="0"> <tbody> <tr> <th nowrap="nowrap" valign="top"> <table bgcolor="#eeeeee" border="0" cellpadding="3" cellspacing="0"> <tbody> <tr> <th nowrap="nowrap" valign="top"> Happy Holidays to All</th> </tr> </tbody> </table> </th> </tr> </tbody> </table> </th> </tr> </tbody> </table> </center>

Dec 22, 2004 3:02 AM in response to Tom_X

Thank you very much for your link, and still more questions SORRY!!!
Let me explain:
I have received animated X'Mas cards from people before and would like to do the same.
I made the card in Flash and have already uploaded it on my website.
With the Script installed, how do I send it using mail? Safari apparently does not have a send web page option. If I use Netscape, I get a link sent instead of the page where my card is.

P.S.- the newsletters we receive from Apple, they are HTML emails, right?

Thank you Tom or anyone else who can help!!!

Dec 22, 2004 11:11 AM in response to Chiuchutrain

Hello Linda - I'll try to help you. 🙂

You wrote: P.S.- the newsletters we receive from Apple, they are HTML emails, right?

Yes, Apple newsletters are HTML emails - and they always use an html TABLE to contain all the text and images - that's the best way to compose an HTML email.
<hr size="2" width="100%"> You wrote: With the Script installed, how do I send it using mail? Safari apparently does not have a send web page option. If I use Netscape, I get a link sent instead of the page where my card is.

Linda, you didn't read the posts above carefully...

Libby Maynard wrote:
Also, it will tell you (the script) this, but you need to create an email with the recipients and subject line before you run it.
You can then either select an html file (on your desktop) OR the "front window" in Safari, which is great.
A note about html emails:
You do need to have the images posted on a server and you must make your file references absolute in your html file (each image will have a complete url e.g. http://www.myserver.com/image1.jpg). <- This is a VERY IMPORTANT statement!!</font>
You can read more about having a complete url to your images here...
Create an HTML eNewsletter/email using Microsoft Outlook Express

<hr size="2" width="100%">You wrote: I made the card in Flash and have already uploaded it on my website.
Linda, I hope a "card in Flash" will display in an HTML email - you will have to test because I do not know if it will or not ¿.
<hr size="2" width="100%">I posted a silly web page for you to test sending an HTML email (the image url is complete). click here to test <-</a>

If you send me the url to your site, I might be able to help a little more.
Also, feel free to send me any test HTML emails and I'll let you know how they view.
Cheers,
Tom X
applediscussion@trysb.net

Dec 22, 2004 11:34 AM in response to Martha

TOM-thank you for all your answers to my questions and thank you very much for the web page you've made me. Before I received your reply, I did manage to figure out how to send Complex HTML via Mail.app. You are so right, I do not have a complete URL for my X'mas card. I'll try to fix that. Hopfully, I can figure everything out before Christmas. Thank you once again for all your help.

Dec 22, 2004 10:34 PM in response to Andreas Amann

Hi Andreas - It was my pleasure adding a little bit to this topic.
I too want to THANK YOU for posting such a brilliant and fun script!
I really think that your script will be around a long time.
I want to show you two topics and I hope you get a laugh from them as I did.
Check the Times on the posts. 😉
Topic: emailing links: Safari vs. IE
Topic: How can I send web pages with Mail?
Cheers,
Tom X

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Sending Complex HTML emails with MAIL

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