Re: Script to send an email using Mail in OS X?
Re: Script to send an email using Mail in OS X?
- Subject: Re: Script to send an email using Mail in OS X?
- From: Jay Young <email@hidden>
- Date: Mon, 15 Apr 2002 20:16:17 -0500
Hi Rob,
I got most of this code from the 'AppleScript In A Nutshell' book.
This is an excellent reference book if you can get a copy. This should
do what you're needing. I've added 'close window 1' to the end of the
script, because if you don't have that, it will leave your composed
message window up, even though it already sent it. Test this out and
see if it works for you.
----------------------------------------------------------
tell application "Mail"
activate
set emailinfo to (make new compose message [NO BREAK]
at the beginning of compose messages with [NO BREAK]
properties {content:"Rob's First Email Script!", subject:"Scripting
Test"})
tell emailinfo to make new to recipient at beginning [NO BREAK]
of to recipients with properties {address:"rob_miller@mac.[NO BREAK]
com", display name:"Rob"}
make new message editor at the beginning of message editors
set the compose message of message editor 1 to emailinfo
send emailinfo
close window 1
end tell
----------------------------------------------------------
Hope it helps!
Jay
On Monday, April 15, 2002, at 10:18 AM, Rob Miller wrote:
>
Hello,
>
>
I'm almost a complete novice with Apple Script, so apologies in advance
>
for the extreme naivety of this question, and many thanks in advance to
>
anyone who can help.
>
>
How can I write a script to get the "Mail" application in OS X to send
>
a simple email? I've been struggling with this for a few days now but
>
have got nowhere. Looking in the "Mail" Script Dictionary, there is a
>
"compose message" object class in the "Mail suite", and a "send"
>
command in the "Message suite". So my guess is that I have to create a
>
new instance of the "compose message" class, set its properties
>
appropriately, and then "send" it. My best effort along these lines is:
>
>
tell application "Mail"
>
set myFirstEmail to (make new compose message)
>
set subject of myFirstEmail to "Message from emailing script"
>
set recipient of myFirstEmail to "email@hidden"
>
set content of myFirstEmail to "Hello Rob!"
>
send myFirstEmail
>
end tell
>
>
But this doesn't even get past the first nested line. One problem is
>
that I see from the dictionary that the "make" command has an "at"
>
parameter, but I haven't any idea what kind of value to give this in
>
the context of a new mail message (except perhaps a "mailbox" container
>
or similar?...).
>
>
I'm using Mac OS 10.1.3, Script Editor 1.7, Mail 1.1 and Apple Script
>
1.8 (I think).
>
>
Help!
>
>
Rob
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.