Need applescript to send an email from Safari

Hi,

I’m ne to applescript. To send stylish html E-mail with embedded pictures from Apple Mail, it seems that the the only solution is Safari.

So I need a script to open a html file in Safari, send this an adds the recipients and attachments to the mail and then send it.

I’m on that point:

  1. open a html file in safari and start to send it works

Code:
tell application “Safari”
set _thispath to “/Users/MyName/Desktop/Mail/myhtml.html”
activate
open (_thispath)
tell front window
email contents of current tab
end tell
end tell

  1. then I needs to access the open message in Mail to add
    a) Recipients
    b) Attachments

But I don’t know to access the safari generated message from applescript, to add the need parameters and send it.

Please help

Model: iMac Late 2009
Browser: Safari 534.59.10
Operating System: Mac OS X (10.8)

Hey There,

The problem you have is that once a message is created in Mail you can’t do anything with it via AppleScript.

The only time you can adjust a message’s attributes with AppleScript is during the initial creation process.

This works:

set _subject to "Test HTML Email"
set _recipient to "me@null.com"
set htmlStr to "<html><body><strong>This is a test</strong><p>and so is this</p></body></html>"

tell application "Mail"
	set newMsg to make new outgoing message with properties {subject:_subject, html content:htmlStr}
	tell newMsg
		make new to recipient at end of to recipients with properties {address:_recipient}
		send
	end tell
end tell

The funky thing is that it only works if sent immediately, which makes writing and debugging a script more difficult.

I’ve tried adding an attachment to this with make new attachment…, but it fails to take. However it might be possible to embed them in the html.

In any case Mail.app is not a very good platform for sending scripted emails. (For shame Apple!)

Really? Have you tried the stationary button up on the right when you are composing a new message?

He’s trying to script it. Stationary is not available in Mail’s AppleScript dictionary.