共用方式為


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

Comments

  • Anonymous
    January 01, 2003
    Thanks Greg for the update

  • Anonymous
    October 14, 2010
    I went to the SPGlobalAdmin page.   It's now an obsolete class.  In the UpdateMailSettings description, it recommends using another API.  Here's the code I used: $ca = get-spsite -Identity "http://$($env:computername):10000"    # the CA app $wa  = $ca.WebApplication $wa.UpdateMailSettings('emailserver', 'fromaddress@contoso.com', 'replyto@contoso.com', 65001)

  • Anonymous
    December 10, 2010
    Thanks! You saved me the day. I use a slightly shorter version of  Your code: $cawebapp = Get-SPwebApplication -includecentraladministration | where {$_.IsAdministrationWebApplication} $cawebapp.UpdateMailSettings('emailserver.contoso.com', 'fromaddress@contoso.com', 'replyto@contoso.com', 65001)