For a concrete example, I just want to reference the code Chris posted earlier on using System Events with Mac Mail. It works great.
See this post:
For more information, see the wiki Searching the Forum for Answers section.