Check for online connection

Is there a way to check for an online connection from a script? I have a script that sends email notifications and I would like it to detect that there is no connection if say a powerbook is in transit and not connected when the script executes. I could probably infer that there is no connection based on errors from the email osax or timeouts, but I’m hoping there is something better.