AppleScript: Create a post to Exchange Public Folder Using Entourage 2004

L

le0pard13

Would anyone in the group have a script/examples for creating a post
(with a file attachment) to an Exchange public folder? I'm using
Entourage version 11.2.5, OS X 10.4.7. TIA
 
P

Paul Berkowitz

Would anyone in the group have a script/examples for creating a post
(with a file attachment) to an Exchange public folder? I'm using
Entourage version 11.2.5, OS X 10.4.7. TIA


I don't think it's possible, but let's see. If you first select this public
folder in the Folders List and Edit/Add to Favorites, so it's now in
Favorites, it can now be accessed by AppleScript. You can get any existing
message in the folder. But I don't see how to post messages to it unless you
are also able to send an email there, using a regular email address. Can you
do that? How exactly do you post messages there manually from Entourage?
(I'm not familiar with how this works, although I do have a test Exchange
account where I could try it out. I do have email access, but as far as I
know, that's a special case, not a normal public folder.)

If you tell me how you do it manually in Entourage (not Outlook nor any
other access), I might be able to do it via AppleScript.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
B

Barry Wainwright [MVP]

I don't think it's possible, but let's see. If you first select this public
folder in the Folders List and Edit/Add to Favorites, so it's now in
Favorites, it can now be accessed by AppleScript. You can get any existing
message in the folder. But I don't see how to post messages to it unless you
are also able to send an email there, using a regular email address. Can you
do that? How exactly do you post messages there manually from Entourage?
(I'm not familiar with how this works, although I do have a test Exchange
account where I could try it out. I do have email access, but as far as I
know, that's a special case, not a normal public folder.)

If you tell me how you do it manually in Entourage (not Outlook nor any
other access), I might be able to do it via AppleScript.


It's possible, but it needs an ugly hack to work round what I suspect is a
bug in Entourage.

tell application "Microsoft Entourage"
set theAccount to first Exchange account
set favFolder to favorites folder of theAccount
set theDestination to folder 1 of favFolder
set newPost to make new outgoing message at end of theDestination with ¬
properties {subject:"Test Post", Exchange post:true}
move newPost to theDestination
end tell

If you tell Entourage to 'make new post' anywhere but an exchange folder,
the script errors, saying posts have to be made in an exchange folder, but
the post is created in the local Drafts folder! (so, the error message is
lying <g>)

That is why I make the post at the end of 'thedestination', and then
immediately move it into 'thedestination'

All other properties of the post, including attachments can be made in the
normal way.
 
L

le0pard13

Barry said:
It's possible, but it needs an ugly hack to work round what I suspect is a
bug in Entourage.

tell application "Microsoft Entourage"
set theAccount to first Exchange account
set favFolder to favorites folder of theAccount
set theDestination to folder 1 of favFolder
set newPost to make new outgoing message at end of theDestination with ¬
properties {subject:"Test Post", Exchange post:true}
move newPost to theDestination
end tell

If you tell Entourage to 'make new post' anywhere but an exchange folder,
the script errors, saying posts have to be made in an exchange folder, but
the post is created in the local Drafts folder! (so, the error message is
lying <g>)

That is why I make the post at the end of 'thedestination', and then
immediately move it into 'thedestination'

All other properties of the post, including attachments can be made in the
normal way.


--
Barry Wainwright
Microsoft MVP (see http://mvp.support.microsoft.com for details)
Check out the Entourage User's WebLog for hints, tips and troubleshooting
<http://homepage.mac.com/barryw/weblog/weblog.html>

Thank you Barry and Paul for your replies. Barry, you sample code works
perfectly for my needs. I've modified it slightly so that it can handle
file attachment:

tell application "Microsoft Entourage"
set theAccount to first Exchange account
set favFolder to favorites folder of theAccount
set theDestination to folder 1 of favFolder
set newPost to make new outgoing message at end of theDestination with
properties {subject:"Test Post", Exchange post:true}
set postFile to "Macintosh HD:Users:Shared:Out:Report Jul 06.pdf"
make new attachment at newPost with properties {file:postFile}
move newPost to theDestination
end tell
 
P

Paul Berkowitz

It's possible, but it needs an ugly hack to work round what I suspect is a
bug in Entourage.

tell application "Microsoft Entourage"
set theAccount to first Exchange account
set favFolder to favorites folder of theAccount
set theDestination to folder 1 of favFolder
set newPost to make new outgoing message at end of theDestination with ¬
properties {subject:"Test Post", Exchange post:true}
move newPost to theDestination
end tell

If you tell Entourage to 'make new post' anywhere but an exchange folder,
the script errors, saying posts have to be made in an exchange folder, but
the post is created in the local Drafts folder! (so, the error message is
lying <g>)

That is why I make the post at the end of 'thedestination', and then
immediately move it into 'thedestination'

All other properties of the post, including attachments can be made in the
normal way.

Well, this is fascinating, Barry. I have discovered a few issues, however:

1) You can, instead, forget about the 'Exchange post:true' property, and
leave out 'at end of' anywhere, and do this:

set newPost to make new outgoing message with properties {subject:"Test
Post 1", content:"Test 1"}
move newPost to theDestination

That gets the post there, too: the only thing it's missing is the cute icon
for Exchange posts. (If you include 'Exchange post:true', you get the error
about having to make Exchange posts only in an Exchange folder.) When you do
it this way, the message appears in the public folder, as it should, bolded
(as unread) and correctly sorted when viewed by Received order (the
default). But see below.


2) When you do it your way, with 'Exchange post:true' to get the icon, then
it does indeed need to be made 'at end of' (or 'at beginning of' - that also
works) some Exchange folder, then moved. (Deep down, all new elements
require insertion at a "location". But good developers implement it do you
don't need to specify 'at end' or 'at beginning': in Entourage, it's never
necessary. Thus this looks like they never intended to facilitate posting to
public folders - it's probably a hack that it works at all. It's also a
"bug", or "feature gap" anyway, that it was not implemented properly.)

The trouble is : the message appears at the very bottom of the list, not the
top, when viewed in Received order, and as soon as the public folder updates
(syncs) with the server, it appears unbolded, as read. (If you don't have
the public folder selected as you run the script, and only go to it
afterwards, you'll see this for yourself. Or else move away and back to the
folder, or do a "Synchronize Now" on it.) So you won't notice that you've
got a new message.

If you check for 'time received' of this message, you'll see there is none
(in AppleScript, it will show as Jan. 1, 1904). This makes sense, since it
was never received in the normal way.

You _could_ get around this by making it an _incoming_ message instead of an
outgoing one. But then you'd have to specify all sorts of things, like the
sender (you). This would get very "iffy", and not comfortable, However, if
you try it, you'll see the message does appear bolded, correctly sorted. It
just doesn't have a sender!



3) Finally, I'm curious to know if any or all of these methods create
messages that are seen by other people on the Exchange server, or if any of
them might not sync to the server. Also, the posts that display in a
less-than-ideal way (no Received time, sorted wrong, viewed as read) may
appear just fine on other computers where in fact they are properly
"received".

Barry, could you please check the BetaFriends public folder you have in
Mailing List Archives folder in Public Folders of our mbubeta Exchange
account, and see if my posts appear there? They're all called "Test Post x",
numbered 1 through 7 (not "x"). Please sort the folder by Received. In my
own case only numbers 1 and 4 are sorted correctly - with Test Post 1 as a
"regular" email icon rather than Exchange, and Test Post 4 appearing without
a sender. Nos. 2, 3, 5, 6, 7 all have the correct Sent time but are at the
wrong end when sorted by Received, and on my computer all appear as Read
although they aren't read yet. On your computer, if you can see them at all,
they might all appear correctly, which would be great if so.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
B

Barry Wainwright [MVP]

Well, this is fascinating, Barry. I have discovered a few issues, however:

1) You can, instead, forget about the 'Exchange post:true' property, and
leave out 'at end of' anywhere, and do this:

set newPost to make new outgoing message with properties {subject:"Test
Post 1", content:"Test 1"}
move newPost to theDestination

That gets the post there, too: the only thing it's missing is the cute icon
for Exchange posts. (If you include 'Exchange post:true', you get the error
about having to make Exchange posts only in an Exchange folder.)

But what you get then is a message, not a post. The two are subtly different
entities in Exchange (a little like the difference between newsgroup
postings and mail messages)

I also seem to recall that you could leave out 'at end' or 'at beginning'
and just use 'at theDestination'. I left the 'at end' in from when I was
trying to get the syntax right for the post to be created in the public
folder.
When you do
it this way, the message appears in the public folder, as it should, bolded
(as unread) and correctly sorted when viewed by Received order (the
default). But see below.


2) When you do it your way, with 'Exchange post:true' to get the icon, then
it does indeed need to be made 'at end of' (or 'at beginning of' - that also
works) some Exchange folder, then moved. (Deep down, all new elements
require insertion at a "location". But good developers implement it do you
don't need to specify 'at end' or 'at beginning': in Entourage, it's never
necessary. Thus this looks like they never intended to facilitate posting to
public folders - it's probably a hack that it works at all. It's also a
"bug", or "feature gap" anyway, that it was not implemented properly.)

Hmm... See above for comment on 'at end of' etc.

Quite likely they never foresaw that people would make posts in this way,
but the hooks are in there and they should work properly.
The trouble is : the message appears at the very bottom of the list, not the
top, when viewed in Received order, and as soon as the public folder updates
(syncs) with the server, it appears unbolded, as read. (If you don't have
the public folder selected as you run the script, and only go to it
afterwards, you'll see this for yourself. Or else move away and back to the
folder, or do a "Synchronize Now" on it.) So you won't notice that you've
got a new message.

If you check for 'time received' of this message, you'll see there is none
(in AppleScript, it will show as Jan. 1, 1904). This makes sense, since it
was never received in the normal way.

You _could_ get around this by making it an _incoming_ message instead of an
outgoing one. But then you'd have to specify all sorts of things, like the
sender (you). This would get very "iffy", and not comfortable, However, if
you try it, you'll see the message does appear bolded, correctly sorted. It
just doesn't have a sender!

There you hit the fundamental difference - messages 'belong' to somebody,
posts 'belong' to the folder.
3) Finally, I'm curious to know if any or all of these methods create
messages that are seen by other people on the Exchange server, or if any of
them might not sync to the server. Also, the posts that display in a
less-than-ideal way (no Received time, sorted wrong, viewed as read) may
appear just fine on other computers where in fact they are properly
"received".

Barry, could you please check the BetaFriends public folder you have in
Mailing List Archives folder in Public Folders of our mbubeta Exchange
account, and see if my posts appear there? They're all called "Test Post x",
numbered 1 through 7 (not "x"). Please sort the folder by Received. In my
own case only numbers 1 and 4 are sorted correctly - with Test Post 1 as a
"regular" email icon rather than Exchange, and Test Post 4 appearing without
a sender. Nos. 2, 3, 5, 6, 7 all have the correct Sent time but are at the
wrong end when sorted by Received, and on my computer all appear as Read
although they aren't read yet. On your computer, if you can see them at all,
they might all appear correctly, which would be great if so.

Unfortunately, I can't at the moment - I don't have the mbubeta account set
up. However, sending a 'post' (my script) to a public folder on my exchange
account syncs immediately and is visible through OWA, where it appears in
bold, with the correct sent & received dates.

Your method (moving an outgoing message) in there also syncs across, but
with the difference that it shows as read, as you found.

Now, try it and open the two different messages! The 'post' opens properly
as a post. The outgoing message opens, but asks for a recipient to be
supplied. Probably not what anyone wants.

However, one downside is that the post remains bolded, even after opening &
reading. If I use 'mark all as read' on the folder, it is then shown as
read, but no other way (in the interface). Probably another bug.
 
P

Paul Berkowitz

But what you get then is a message, not a post. The two are subtly different
entities in Exchange (a little like the difference between newsgroup
postings and mail messages)

I also seem to recall that you could leave out 'at end' or 'at beginning'
and just use 'at theDestination'.

No, you can't do that. That's where you again get the error, as you had
noted the first time. You really do need 'at end' or 'at beginning' - a
brilliant discovery of yours, since nowhere else in all of Entourage
scripting is tat necessary (unlike several iApps, where it's needed
everywhere - they did fix it in Address Book, however). That's why I think
the analysis that they never intended or thought of getting this to work is
correct - it just works, as you say below, because "the hooks are there".
They never tested it.
I left the 'at end' in from when I was
trying to get the syntax right for the post to be created in the public
folder.

You needed to do that. Any Exchange folder will do for making a message on
the exchange account - but if you want the 'Exchange post:true' then it
doesn't work without the 'at end of': nutty. ;-)
Hmm... See above for comment on 'at end of' etc.

Quite likely they never foresaw that people would make posts in this way,
but the hooks are in there and they should work properly.
Right.


There you hit the fundamental difference - messages 'belong' to somebody,
posts 'belong' to the folder.

It's not just that: any 'outgoing message' where the account is specified or
implied will have the right sender, whereas making a "new" incoming message
(which is a hack for us scripters only, that allows for messages to be
replicated as if imported, for example, by script - it can never be done in
the UI, and some people find it verging on the "impossible" - it can't be
done in Apple Mail) in any context, not just posting, requires the sender
info. For example, in all my scripts that facilitating importing, the sender
info for 'incoming messages' that I create comes across from replicating the
source of an exported message somewhere. You're not really meant to make
incoming messages, just get them. I think this is something best forgotten
about. I just wanted to try it.
Unfortunately, I can't at the moment - I don't have the mbubeta account set
up. However, sending a 'post' (my script) to a public folder on my exchange
account syncs immediately and is visible through OWA, where it appears in
bold, with the correct sent & received dates.

That's very good. That's what I was hoping.
Your method (moving an outgoing message) in there also syncs across, but
with the difference that it shows as read, as you found.

Actually on my own machine, moving an outgoing message without the 'Exchange
post:true' showed as bold, unread (same with the defective incoming
message). It was just the outgoing messages (pots) with 'Exchange post:true'
that showed up - OMM - as read, and out of received order. This makes sense,
because OMM I'm _uploading_ the posts when they're moved - so when
synchronized with the server Entourage is recognizing that they were already
in my cache, O guess, and assumes 'read' (a minor bug). As I had hoped, on
other machines, where the messages are actually _downloaded_ to the cache,
they are perceived as unread, received messages and are displayed bolded and
sorted correctly (?). Did you view them in Received order? Is it OK?
Now, try it and open the two different messages! The 'post' opens properly
as a post. The outgoing message opens, but asks for a recipient to be
supplied. Probably not what anyone wants.

Right. But that does not occur here with my 'outgoing message' that did not
include 'Exchange post:true'. I can't test an OWA or another computer,
however, so thanks for checking. (Mind you, I see that some old Exchange
posts, pre-dating March 29, 2006, are also missing the icon. Odd. Although
all messages at that period were sent from Entourage 11.2.3, I think I
probably didn't sync to server after mar 27 until 11.2.4 came out. That's
probably the difference.)
However, one downside is that the post remains bolded, even after opening &
reading. If I use 'mark all as read' on the folder, it is then shown as
read, but no other way (in the interface). Probably another bug.

That only happens with my 'outgoing message' (non-post) here. Since all my
Exchange posts are already unbolded I can't check for that.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
Top