Summary
SharePoint and general app servers often use the SMTP Service to integrate e-mail into the systems functionality. Since Windows supports a well vetted SMTP Service, using the built-in application is often the best choice. With the said, when testing your app functionality with e-mail, Telnet is almost always needed and not installed by default.
If find yourself always rebuilding servers to test new features and functionality, you may install SMTP and Telnet manually each time. If this is the case, why not use PowerShell?
What does the script do?
If SMTP is not installed, the installation will proceed. Once completed, it will then detect if Telnet is already installed. If not, you will be asked if Telnet should be installed. If you run the script a server with SMTP or Telnet already installed, the app installation will be detected and skipped.
I’m hoping this script will make your test builds quicker and more enjoyable in the future.
The Script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# Check if SMTP is installed before installing it. $smtp = get-WindowsFeature "smtp-server" if(!$smtp.Installed){ write-host "SMTP is not installed, installing it..." -ForegroundColor red add-WindowsFeature $smtp } else{ write-host "SMTP is already installed!" -ForegroundColor Cyan sleep 2 } #Once SMTP is installed, prompt to install Telnet, if not installed. $telnet = get-WindowsFeature "telnet-client" if(!$telnet.Installed){ #Use a popup windows with a yes or no choice $shell = new-object -comobject "WScript.Shell" $choice = $shell.popup("Telnet is not installed, do you want to install it?",0,"Install Telnet",4+32) } else{ write-host "Telnet is already installed, done!" -ForegroundColor Green break } #If you get here telnet is not installed and the user choose Yes. if ($choice -eq "6"){ write-host "Installing Telnet..." -ForegroundColor Green Add-WindowsFeature $telnet write-host "Done!" -ForegroundColor Cyan } #If you got here telnet is not installed but the user chose No. if ($choice -eq "7" -and !$telnet.Installed){ write-host "Telnet is not installed and will not be installed!" -ForegroundColor Green break } |
The Output:
Here is what you will see if SMTP and Telnet is not installed:
Windows Popup asking if Telnet should be installed:
Installing Telnet:
Done:
If SMTP and Telnet is already installed it be detected and skip the installation: