Blog Post

Microsoft SharePoint Blog
2 MIN READ

Install SMTP Server and Telnet with PowerShell

mikeleemsft's avatar
mikeleemsft
Icon for Microsoft rankMicrosoft
Jan 03, 2019

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 you 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:

 

# 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:

 

 

Published Jan 03, 2019
Version 1.0
  • raghuchandra89's avatar
    raghuchandra89
    Copper Contributor

    Does anyone have a Powershell script to configure the SMTP server? like: 


    Go to the Delivery tab.

     

    Then click Outbound Security. Here you specify the way of authentication on the external mail server to which your SMTP server will send (relay) all email messages. For example, if all emails will be forward to Gmail mail server and then sent to the recipients, you need to check the Basic authentication and specify your Gmail mailbox credentials (you must allow to send email via Gmail SMTP in the Google account settings).

     

     

    Then click Advanced.

     

     

    Here you specify the FQDN name of your SMTP server. Click the Check DNS button to make sure that the DNS record is valid.

     

     

    If your server sends mail to an external SMTP server, specify its name in the Smart host field (for example, smtp.gmail.com or smtp.office365.com).

    Some public mail servers accept email only when using a secure SMTP connection using TLS Encryption (TCP port 587). You can configure this setting in the section Delivery -> Outbound Security and Outbound Connections. Read the documentation of your email provider.

    Save the SMTP server settings and restart your SMTP virtual service to apply the changes.

  • Hwid22's avatar
    Hwid22
    Copper Contributor

    You can find SMTP configuration at location C:\Windows\System32\inetsrv\MetaBase.xml
    Then copy settings to new SMTP host.

    To be able to save MetaBase.xml, you need to stop services.

    Get-Service SMTPSVC | Stop-Service

    Get-Service IISADMIN | Stop-Service

     

    Then just start service again.

    Btw, Notepad++ is a great xml editor.