Here's the AppleScript: The script checks to see if Mail is running, if it is, and it has not been running for longer than five seconds (of processor time), then it checks to see if the server work-server is available, and enables/disables the Mail account Work as appropriate. Obviously, you'll need to customize those values for your situation.
We also need a way to run this AppleScript automatically; for that we create a Launch Agent: Save the above as net.checkmail.servers.plist in your user's Library » LaunchAgents folder, and it will run automatically when Mail's plist changes (which happens every time you launch Mail). Good luck!
[robg adds: I haven't tested this one, and note you'll need to edit both code snippets to match your setup.]

