Frequently people receive e-mail at a "public" mail address, which may even be an alias that forwards the mail on to another address. In reply, you might want to send from a different address. Sometimes, when sending a new (non-reply) message, Microsoft Entourage will naturally send it from the default account unless you remember to change the account manually. You want to be able to send mail automatically from the correct account, especially in business.
By creating a category with the same name as the mail account, and then assigning this category to contacts in your Address Book to whom you want correspondence to be sent only from that account, this script will make it possible. You need to run it from a repeating schedule every one minute so that it catches the message window before you send it, and changes the account while you're writing.
You need to enter the name of each account/category. Each one should be in its own set of quotes, separated by commas, and in the otherAccountNames property list braces, like this:
{"Correspondence", "billing@mybusiness.com"}. Some people use the actual e-mail address to name their mail accounts, and some give descriptive names. You must use whatever the names are as they appear in Tools > Accounts > Mail, without the POP, IMAP, or Exchange
description.
(*enter account/category names in {},
comma-separated "quoted text" items*)
property otherAccountNames : {}
tell application "Microsoft Entourage"
if otherAccounts = {} then
beep
return
end if
try
set frontWin to front window
if class of frontWin ≠ draft window then
return -- quit if no new draft window open
end if
on error
return
end try
set recipsList to every recipient of frontWin
set exitRpt to false -- for outer loop
repeat with i from 1 to count recipsList
repeat 1 times
set theRecip to item i of my recipsList
set eAddress to address of the address of theRecip
if eAddress ≠ "" then
try
set foundItem to item 1 ¬
of (find eAddress)
on error -- not a contact
exit repeat -- 1 times
end try
else -- group
try
set dName to display name of address ¬
of theRecip
set foundItem to group dName
on error
-- text typed in without being group
-- or email address
exit repeat -- 1 times
end try
end if
set theCats to category of foundItem
if theCats = {} then exit repeat
repeat with j from 1 to (count theCats)
set catname to name of (item j of theCats)
if {catname} is in otherAccountNames then
try
set otherAccount ¬
to POP account catname
on error
try
set otherAccount ¬
to IMAP ¬
account catname
on error
try
set otherAccount ¬
to ¬
Exchange ¬
account ¬
catname
on error
beep 2
return
end try
end try
end try
tell frontWin to set its account ¬
to otherAccount
set exitRpt to true
exit repeat
end if
end repeat
end repeat -- 1 times
if exitRpt then exit repeat -- done
end repeat
end tellNote that the script checks for every recipient. If all you care about is the first To recipient, remove the outer
repeat
block and
exitRpt
lines, and do the following instead:
set theRecip to first recipient of frontWin
AppleScript does not have a
Next Repeat
operator, so note the alternative in the script to effect the same thing by including a
repeat 1 times
block inside the outer
repeat
block. That way, when you hit a condition that makes continuation with the current list item unnecessary and undesirable (for example, when no recipient is a contact or group bearing the sought category), the script moves on to the next list item by an
exit repeat
within the
repeat 1 times
block, rolling it forward to the next item in the outer
repeat
loop.
That's why, when there's a condition that requires exiting the outer
repeat
block, namely having found both a category and the account of the same name, you first have to set the variable
exitRpt
to true, exit the inner
repeat 1 times
block, and use the true value of
exitRpt
after the
repeat 1 times
block closes as the criterion for
exit repeat
from the outer block.
Also note that there's no generic
account
class (although message has an account property), so you need to check for POP account, IMAP account, and Exchange account of the designated name in turn.


