Re: Trying to send mail with attachments through Entourage
Re: Trying to send mail with attachments through Entourage
- Subject: Re: Trying to send mail with attachments through Entourage
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 17 Dec 2006 09:11:29 -0800
- Thread-topic: Trying to send mail with attachments through Entourage
Title: Re: Trying to send mail with attachments through Entourage
On 12/17/06 7:57 AM, "Bryan Lockwood" <email@hidden> wrote:
> I am trying to create an AppleScript to that will use Entourage to generate
> a new message, address it properly, and then add all the PDF files that are
> found where the scanner software left them. Seems straightforward. I can
> create a new message easily enough:
>
> tell application "Microsoft Entourage"
> set msg to make new outgoing message with properties {subject:"XXX"}
> end tell
>
>> From here on, though, I am baffled. Statements like "make new recipient" or
> "make new attachment" are flatly rejected as impossible requests.
>
> Can anyone give me a clue here? It would be greatly appreciated.
Assuming you are actually trying to make a new outgoing message to be sent without opening it for any manual additions such as the content (in which case you'd be better off making a 'new draft window' rather than 'outgoing message') you are on the right track. All the properties (subject, content, account, priority, etc.) can easily be set at inception in the 'with properties' parameter above. The problem you're facing is with creating the elements - recipients and attachments. Normally, you're quite correct, you'd expect to create these _at_ the message after the message exists. And, in fact, it is possible to do that with attachments. You have correctly set a variable to the result of the 'make new outgoing message' to have something to make the attachment at:
make new attachment at msg with properties {file:alias "Mac HD:Users:you:Pictures:Scanner Dump:FileName abcdef.pdf"}
and you could them all one by one. But that's pretty tedious. Also, as you may have discovered, you can't do this for recipient elements even if you get the syntax right: the reason for this is that once an email message has been encoded for sending you can't interfere with it (behind the scenes, headers need to be added for recipients, and so on, and it's too late for it to be done automatically once the message is encoded. That's why it can be simpler to make a new draft window, where the various recipient properties are just text.)
There is an undocumented feature whereby you can add as many recipients as you need via a putative 'recipient' property. You can't _get_ this property from an existing message, only when you're making a new one. All the properties of recipient - address, display name, recipient type - listed under recipient in the dictionary (including the confusing fact that it has an 'address' property which itself has the actual 'address' and 'display name' text properties) are available. If you are just using a single 'to recipient', you can omit a lot of the specifications, taking advantage of the fact that 'to recipient' is the default recipient type, and you can also use a "Display Name <eaddress@domain>" shorthand, also undocumented:
set msg to make new outgoing message with properties {subject:"XXX", content: recipient:"Joe Blow <email@hidden>"}
(Since this doesn't specify _where_ to make it, it does so in the local Drafts folder, using the default account. These can all be specified otherwise, if you wish.)
But the full syntax lets you specify as many recipients as you want, of whichever recipient types you want, setting a list of all the recipients to the 'recipient' property. You also use braces for each recipient, since each one is a record (containing 'address' and 'recipient type') where each 'address' is also a record (containing 'address' and 'display name'). That makes for a lot of braces:
tell application "Microsoft Entourage"
set msg to make new outgoing message with properties {subject:"XXX", content:"Some text here", recipient:{{address:{address:"email@hidden", display name:"Joe Blow"}, recipient type:to recipient}, {address:{address:"email@hidden", display name:"Jane Blow"}, recipient type:cc recipient}, {address:"email@hidden", display name:"Ebenezer Scrooge", recipient type:bcc recipient}}}
end tell
(That's just one recipient per type: you can include as many as you wish, of course, in the list. You can omit recipinet type if it's a 'to recipient', and you can omit display names.)
Now, there's also a similar "putative" 'attachment' property you can use in exactly the same way, especially useful when you need to make many attachments, as you seem to. Make a list of them first, and use the list as the 'attachment' property. (Once again, if you're making only one, you can omit the list braces.) If you already have a list of aliases from the Finder, even better, since you can just include that list and forget about setting the 'file' property for each attachment! (Another undocumented shortcut):
tell application "Finder"
try
set attchList to every file of alias "Mac HD:Users:you:Pictures:My Pictures:2005-04-26:" as alias list
on error -- only one file
set attchList to every file of alias " Mac HD:Users:you:Pictures:My Pictures:2005-04-26:" as alias as list
end try
end tell
tell application "Microsoft Entourage"
set msg to make new outgoing message with properties {subject:"XXX", content:"Some text here", recipient:{{address:"email@hidden", display name:"Joe Blow"}, {address:{address:"email@hidden", display name:"Jane Blow"}, recipient type:cc recipient}}, attachment:attchList}
end tell
(Here I used a shortcut for the 'to recipient'.) Don't forget to include the try/error for 'alias list' in case there's only one file.
Does this go most of the way to answering your question?
--
Paul Berkowitz
_______________________________________________
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/mailman//archives/applescript-users
This email sent to email@hidden