Powershell script to change SMTP configuration

Hi!

I have a powershell script which I'm using to set up a number of identical Server 2008 R2 boxes.  We have the microsoft SMTP service installed (as "virtual server #1") but I can't find Powershell code to change the properties such that the SMTP service (which can only be manipulated via IIS 6 manager) allows the local system to relay through it.  We have both an application (and the PS script) that need to be able to send emails, but it only works if we set the local relay to be allowed.

Security is not an issue on the open relay.

I've seen references to VB, and even one to a purchasable cmdlet - neither of which are really options.

Ideas?

Thanks in advance!

Lee

August 11th, 2011 9:23pm

http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/1ec56a85-39e8-409c-b351-5d7017c1f7d9

If that doesn't help, please provide the VB reference, and maybe we can convert it.  As for the cmdlet, I doubt it configures the SMTP service itself...

Free Windows Admin Tool Kit Click here and download it now
August 11th, 2011 9:47pm

I saw that thread, but it utilizes the VBS script adsutil; I'm *really* trying to avoid going that route.

I think I may have it.  This uses the ADSI reference mechanism to get and set parameters.  I am testing it right now.

$SMTPServer = [ADSI]"IIS://localhost/smtpsvc/1"

 

$SMTPServer.RelayForAuth = -1

$SMTPServer.SetInfo()

... and that failed. I think I need to add an SMTPServer.RelayIPList entry, but it must be in octal if I read correctly.

 


August 11th, 2011 10:06pm

That's not flying, either.  

The RelayForAuth does check the box in IIS6 manager; but I can't get an entry in to the IP list (although, in theory, I shouldn't have to since the box is checked.)  I'm stumped.

Lee

Free Windows Admin Tool Kit Click here and download it now
August 11th, 2011 11:38pm

Here is the powershell code for adding ips to relayiplist..hope this helps.

this code will take the ips of the host machine and add it to the relayiplist...works for me...

$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName localhost | ? {$_.IPEnabled}
$ipblock= @(24,0,0,128,
32,0,0,128,
60,0,0,128,
68,0,0,128,
1,0,0,0,
76,0,0,0,
0,0,0,0,
0,0,0,0,
1,0,0,0,
0,0,0,0,
2,0,0,0,
1,0,0,0,4,0,0,0,0,0,0,0,76,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255)
$ipList = @()
$octet = @()
foreach ($Network in $Networks)
   {
     $ipList = $Network.IpAddress[0]
        $octet += $ipList.Split(".")
        $ipblock[36] +=1
        $ipblock[44] +=1;
   }

$smtpserversetting = get-wmiobject -namespace root\MicrosoftIISv2 -computername localhost -Query "Select * from IIsSmtpServerSetting"
$ipblock += $octet
$smtpserversetting.RelayIpList = $ipblock
$smtpserversetting.put()

January 28th, 2015 12:26am

http://stackoverflow.com/questions/30031514/configure-smtp-virual-server-in-windows-server-using-powershell-relay-connectio

Here i followed the same code to set relay and connection.

But smtp virtual server get crashed , i am unable to open it. 


Free Windows Admin Tool Kit Click here and download it now
May 6th, 2015 9:26am

HI kautilya ,

the above answer works great , but could you explain what is ipblock[36] , ipblock[44]. it some way working.

Vimal


May 8th, 2015 12:19am

HI kautilya ,

the above answer works great , but could you explain what is ipblock[36] , ipblock[44]. it some way working.

Vimal


Free Windows Admin Tool Kit Click here and download it now
May 8th, 2015 12:21am

HI kautilya ,

the above answer works great , but could you explain what is ipblock[36] , ipblock[44]. it some way working.

Vimal


May 8th, 2015 4:17am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics