Re: Apple Mail - Sending to multiple recipients
Re: Apple Mail - Sending to multiple recipients
- Subject: Re: Apple Mail - Sending to multiple recipients
- From: John <email@hidden>
- Date: Sat, 12 Jan 2013 10:15:40 -0500
Hi Simon,
Try:
script s
property kEmailRec : missing value
on init()
set kEmailRec to ¬
{_subject:"This is the subject" as text ¬
, _body:"This is the body" as text ¬
, _to:{} ¬
}
end init
on addTestData()
repeat with i from 1 to 1000
set end of kEmailRec's _to to {"test" & i & "@
example.com"}
end repeat
end addTestData
end script
s's init()
s's addTestData()
set xxx to s's kEmailRec's _to
set {TID, text item delimiters} to {text item delimiters, ", "}
set xxx to xxx as text
set text item delimiters to TID
tell application "Mail"
activate
set mymail to make new outgoing message at the beginning of outgoing messages with properties {subject:s's kEmailRec's _subject}
tell mymail
make new to recipient at beginning of to recipients with properties {address:xxx}
--make new attachment with properties {file name:alias "Mac OS X:Users:John:Desktop:Test Folder2:6.pdf"}
set content to s's kEmailRec's _body
end tell
--show message window (otherwise it's hidden)
set visible of mymail to true
--bring Mail to front
activate
--send mymail
end tell
John D.
On Sat, Jan 12, 2013 at 9:52 AM, Simon Topliss
<email@hidden> wrote:
Hi all,
Does anyone have any tips on how to speed up creating a "to recipient" list in Mail?
The following script takes about 2 minutes to create a new message for 500 recipients and about 8 minutes to create 1000 recipients. I need to be able to create a new message for 4000+ recipients but it takes way too long to be practical as things stand.
--------------------------------------------------------------
script s
property kEmailRec : missing value
on init()
set kEmailRec to ¬
{_subject:"This is the subject" as text ¬
, _body:"This is the body" as text ¬
, _to:{} ¬
}
end init
on addTestData()
repeat with i from 1 to 1000
set end of kEmailRec's _to to {"<test" & i & "@example.com>"}
end repeat
end addTestData
end script
s's init()
s's addTestData()
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:s's kEmailRec's _subject, content:s's kEmailRec's _body & return & return}
tell newMessage
repeat with i from 1 to s's kEmailRec's _to's length
make new to recipient at end of to recipients with properties {address:item i of s's kEmailRec's _to}
end repeat
set visible to true
end tell
activate
end tell
--------------------------------------------------------------
I've tried the usual 'repeating with a script object's property' but it didn't make much difference.
I suspect that the slowness is due to having to send an Apple Event every time to 'make new recipient at end' in the repeat loop.
I've tried building the list outside of Mail with raw syntax like this:
--------------------------------------------------------------
on addTestData()
repeat with i from 1 to 1000
set end of kEmailRec's
_to to {«
class radd»:
"<test" &
i &
"@example.com>"}
end repeat
end addTestData
--------------------------------------------------------------
And then setting the 'to recipients' in one go like this:
--------------------------------------------------------------
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:s's kEmailRec's _subject, content:s's kEmailRec's _body & return & return}
tell newMessage
set to recipients to s's kEmailRec's _to
set visible to true
end tell
activate
end tell
--------------------------------------------------------------
But that errors with "Mail got an error: Can’t make {{address:"<
email@hidden>"}, {address:"<
email@hidden>"}, …etc} into type to recipient." That's probably because I'm setting the 'to recipients' as a list of properties, rather than a list of 'to recipients'.
Any ideas?
Simon
_______________________________________________
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
_______________________________________________
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