This script allows to configure outgoing e-mail settings in a SharePoint farm. The script defines a function that uses the Get-SPWebApplication cmdlet in order to obtain the Web Application for the SharePoint Central Administration. Once this Web Application is read, the script simply set the parameters for the outgoing e-mail settings.

 

PowerShell
Editar script|Remove
############################################################################################################################################ 
# Script to configure outgoing e-mail in SharePoint 
# Required Parameters:  
#    ->$sSMTPServer: SMTP Server. 
#    ->$sFromEMail: From Address. 
#    ->$sReplyEMail: To Address. 
#    ->$sChartSet: Character Set. 
############################################################################################################################################ 
 
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )  
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } 
 
 
$host.Runspace.ThreadOptions = "ReuseThread" 
 
#Definition of the function that configures outgoing e-mail in SharePoint 
function Configure-OutGoingEMail 
{ 
    param ($sSMTPServer,$sFromEMail,$sReplyEmail,$sCharSet) 
    try 
    {    
        $CAWebApp = Get-SPWebApplication -IncludeCentralAdministration | Where { $_.IsAdministrationWebApplication } 
        $CAWebApp.UpdateMailSettings($sSMTPServer$sFromEMail$sReplyEmail$sCharSet) 
        write-host -f Blue "Outgoing e-mail configured"                
    } 
    catch [System.Exception] 
    { 
        write-host -f red $_.Exception.ToString() 
    } 
} 
 
Start-SPAssignment –Global 
 
#Required Objects 
$sSMTPServer='<SMTP_Server>' 
$sFromEMail='<From_EMail>' 
$sReplyEmail='<Reply_EMail>' 
$sChartSet=65001 
 
#Calling the function 
Configure-OutGoingEMail -sSMTPServer $sSMTPServer -sFromEMail $sFromEMail -sReplyEmail $sReplyEmail -sCharSet $sChartSet 
 
Stop-SPAssignment –Global