How to set up SMTP Relay with IIS 6.0 using Exchange Online
Introduction
This script will help administrator to set up SMTP Relay.
Scenarios
This script is to help administrator to set up SMTP Relay without configuring step by step.
Script
You can use this script in the following way.
1. Open Windows PowerShell.
2. Type the one command< Script Path> at the Windows PowerShell Console.
For example, type C:\Script\ EXOSetUpSMTPRelay.ps1
Here are some code snippets for your references.
$setting = Get-WMIObject -class IIsSmtpServersetting -namespace "root\microsoftiisv2" $bindings = $setting.ServerBindings $bindings[0].IP = $LocalIPAdd $bindings[0].Port = 587 $setting.ServerBindings = $bindings $setting.AuthAnonymous = $true $setting.RemoteSmtpPort = 587 $setting.RouteAction = 268 $setting.RouteUserName = $EXOUserName $setting.RoutePassword = $EXOUserPwd $setting.SmartHost = "smtp.office365.com" $setting.put()
$setting = Get-WMIObject -class IIsSmtpServersetting -namespace "root\microsoftiisv2" $bindings = $setting.ServerBindings $bindings[0].IP = $LocalIPAdd $bindings[0].Port = 587 $setting.ServerBindings = $bindings $setting.AuthAnonymous = $true $setting.RemoteSmtpPort = 587 $setting.RouteAction = 268 $setting.RouteUserName = $EXOUserName $setting.RoutePassword = $EXOUserPwd $setting.SmartHost = "smtp.office365.com" $setting.put()
Example: set up SMTP Relay
The sample is showed below
EXOSetUpSMTPRelay.ps1 -LocalIPAdd 192.168.1.1 -EXOUserName admin@contoso.onmicrosoft.com -EXOUserPwd Password
-GrantByDefault $true -IpListPath "c:\blockeduser.csv"
The CSV should using the following format:
Prerequisites
Exchange Online
Windows PowerShell 2.0
Windows Server 2008 or Windows Server 2008
R2
Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.