Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, May 8, 2013 8:40 PM
I have a powershell script to set the SMTP configuration on new servers (Server 2012) and send a test email
But it doesn't seem to work until you open the IIS6 manager and the properties of the SMTP virtual server then close it. You don't have to change anything just open and click ok. until you do that the email is stuck in the C:\inetpub\mailroot\Queue
# Set SMTP
Write-Host -Foregroundcolor Red " Configuring SMTP "
Set-Service "SMTPSVC" -StartupType Automatic -ErrorAction SilentlyContinue
Start-Service "SMTPSVC" -ErrorAction SilentlyContinue
$SmtpConfig = Get-WMIObject IISSMTPServerSetting -Namespace root/MicrosoftIISv2
$Relay = @(24,0,0,128,32,0,0,128,80,0,0,128,88,0,0,128,1,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,104,0,0,128,2,0,0,0,2,0,0,0,4,0,0,0,0,0,0,0,96,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,127,0,0,1,255,255,0,0,172,20,0,2)
$SmtpConfig.RelayIPList = $Relay
$SmtpConfig.SmartHost="smtp.mydomain.com"
$SmtpConfig.DontLog=$False
$SmtpConfig.LogExtFileBytesRecv=$True
$SmtpConfig.LogExtFileBytesSent=$True
$SmtpConfig.LogExtFileClientIp=$True
$SmtpConfig.LogExtFileComputerName=$True
$SmtpConfig.LogExtFileCookie=$false
$SmtpConfig.LogExtFileDate=$True
$SmtpConfig.LogExtFileFlags=1110127
$SmtpConfig.LogExtFileHost=$True
$SmtpConfig.LogExtFileHttpStatus=$False
$SmtpConfig.LogExtFileHttpSubStatus=$False
$SmtpConfig.LogExtFileMethod=$False
$SmtpConfig.LogExtFileProtocolVersion=$False
$SmtpConfig.LogExtFileReferer=$False
$SmtpConfig.LogExtFileServerIp=$True
$SmtpConfig.LogExtFileServerPort=$True
$SmtpConfig.LogExtFileSiteName=$False
$SmtpConfig.LogExtFileTime=$True
$SmtpConfig.LogExtFileTimeTaken=$True
$SmtpConfig.LogExtFileUriQuery=$False
$SmtpConfig.LogExtFileUriStem=$False
$SmtpConfig.LogExtFileUserAgent=$False
$SmtpConfig.LogExtFileUserName =$True
$SmtpConfig.LogExtFileWin32Status=$False
$SmtpConfig.LogFileDirectory="C:\Windows\System32\LogFiles"
$SmtpConfig.LogFilePeriod=1
$SmtpConfig.LogFileTruncateSize=19922944
$SmtpConfig.LogType=1
$null = $SmtpConfig.put()
# Test SMTP Setting
$SMTPCurrentConfig = Get-WMIObject IISSMTPServerSetting -Namespace root/MicrosoftIISv2
$smtpServer = "localhost"
$smtpPort = 25
$emailFrom = $SMTPCurrentConfig.PSComputerName+"@mydomain.com"
$emailTo = "[email protected]"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Port = $smtpPort
$subject = "Test SMTP " + $SMTPCurrentConfig.DefaultDomain
$Body = $SMTPCurrentConfig.PSComputerName
$smtp.Send($emailFrom, $emailTo, $subject, $body)
All replies (4)
Wednesday, May 8, 2013 9:12 PM âś…Answered
Not that this is super useful but it looks like there is some additional configuration you need to do to get IIS running correctly. Launch Procmon and capture what happens when you open IIS for the first time. Maybe it needs to register some component or write some registry entry.
Hope that helps! Jason
Friday, May 10, 2013 4:43 PM
Jason, You were right after I added the following additional config settings it started working!
$SmtpConfig.SmartHostType=2
$SmtpConfig.SmtpAqueueWait=-1
$SmtpConfig.SmtpAuthTimeout=0
$SmtpConfig.SmtpBdatTimeout=0
$SmtpConfig.SmtpConnectTimeout=0
$SmtpConfig.SmtpDataTimeout=0
$SmtpConfig.SmtpDisableRelay=$True
$SmtpConfig.SmtpDomainValidationFlags=-1
$SmtpConfig.SmtpDotStuffPickupDirFiles=$True
$SmtpConfig.SmtpDSNLanguageID=0
$SmtpConfig.SmtpDSNOptions=0
$SmtpConfig.SmtpEventlogLevel=-1
$SmtpConfig.SmtpHeloNoDomain=$True
$SmtpConfig.SmtpHeloTimeout=0
$SmtpConfig.SmtpInboundCommandSupportOptions=7697601
$SmtpConfig.SmtpIpRestrictionFlag=0
$SmtpConfig.SmtpLocalDelayExpireMinutes=720
$SmtpConfig.SmtpLocalNDRExpireMinutes=2880
$SmtpConfig.SmtpMailFromTimeout=0
$SmtpConfig.SmtpMailNoHelo=$True
$SmtpConfig.SmtpMaxRemoteQThreads=-1
$SmtpConfig.SmtpOutboundCommandSupportOptions=7
$SmtpConfig.SmtpRcptToTimeout=0
$SmtpConfig.SmtpRemoteDelayExpireMinutes=720
$SmtpConfig.SmtpRemoteNDRExpireMinutes=2880
$SmtpConfig.SmtpRemoteProgressiveRetry=("15","30","60","240")
$SmtpConfig.SmtpRemoteRetryThreshold=3
$SmtpConfig.SmtpRsetTimeout=0
$SmtpConfig.SmtpSaslTimeout=0
$SmtpConfig.SmtpSSLCertHostnameValidation=$True
$SmtpConfig.SmtpSSLRequireTrustedCA=$True
$SmtpConfig.SmtpTurnTimeout=0
$SmtpConfig.SmtpUseTcpDns=-1
$SmtpConfig.UpdatedDefaultDomain=$True
$SmtpConfig.UpdatedFQDN=$True
$SmtpConfig.Win32Error=0
Friday, May 10, 2013 5:33 PM
That's great news! You should turn that into a tool and post it up on the repository, stuff like that is really useful and it saves someone else from having to do that level of troubleshooting.
Hope that helps! Jason
Wednesday, May 6, 2015 1:29 PM
Hey i tried this solution but SMTP virtual server gets crashed .