Incoming E-Mail service

May 9, 2011 at 1:00 PM
Edited May 9, 2011 at 4:03 PM

The current script only sets up the outbound email service, not the inbound. The following code could be adapted to include a basic inbound email service in the installation. It does not include configuration of the directory management service, although adding it should only require setting more properties on $IncomingMailService

Import-Module ServerManager

#Install the SMTP server
$smtpfeature=Get-WindowsFeature SMTP-Server
if ($smtpfeature.Installed) {
	Write-Host "SMTP Server already installed"
}
else 
{
	Write-Host "Installing SMTP Server..."
	Add-WindowsFeature SMTP-Server
}

#Boost the maximum message size to 10Mb - this should go in the XML config file
cscript C:\Inetpub\AdminScripts\adsutil.vbs SET SMTPSVC/MaxMessageSize 10485760

#Enable logging
cscript C:\Inetpub\AdminScripts\adsutil.vbs SET SMTPSVC/LogType 1

#Set startup type
Set-Service SMTPSVC -StartupType Automatic

#Ensure it is running
Start-Service SMTPSVC


#Obtain a reference to the SharePoint incoming email service application
$loadasm = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$IncomingMailService = [Microsoft.SharePoint.Administration.SPServiceCollection].GetMethod("GetValue",[String]).MakeGenericMethod([Microsoft.SharePoint.Administration.SPIncomingEmailService]).Invoke($Farm.Services,"")

#Enable sharepoint incoming email
$IncomingMailService.Enabled=$true
$IncomingMailService.UseAutomaticSettings=$true
$IncomingMailService.Update()


#Configure permissions on drop folder
$Acl = (Get-Item "C:\Inetpub\mailroot\drop").GetAccessControl("Access")
$Ar = New-Object  system.security.accesscontrol.filesystemaccessrule("WSS_ADMIN_WPG","FullControl","ContainerInherit, ObjectInherit","None","Allow")
$Acl.AddAccessRule($Ar)
$Ar2 = New-Object  system.security.accesscontrol.filesystemaccessrule("WSS_WPG","Read","ContainerInherit, ObjectInherit","None","Allow")
$Acl.AddAccessRule($Ar2)
Set-Acl -aclobject $Acl "C:\Inetpub\mailroot\drop"