Script Outgoing Email settings in 2007 and 2010

SharePoint doesn't have a cmdlet for this feature yet. I created a bug for the developers to create this PowerShell feature in SharePoint 2010 SP1. Here is the code you can use for now that uses the SharePoint Object Model:

$loadasm = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$SPGlobalAdmin =  New-Object Microsoft.SharePoint.Administration.SPGlobalAdmin
$SPGlobalAdmin.UpdateMailSettings( "emailserver", "fromaddress@microsoft.com", "replyto@microsoft.com", 65001)

Here is a sceenshot from the UI. It is under Central Administration -> System Settings -> Outgoing E-Mail Settings