Testing Open Relay / Allowed Relay using PowerShell

In my previous post, I posted a script which emails me move reports from office 365. A subset of that script emails using a non-authenticated connection.  This code allows you to test an open relay too… In many ways much easier than using Telnet. So here is that code again. 

     #SMTP server name
      $smtpServer = "relay.domain.com"
     #Creating a Mail object
      $msg = new-object Net.Mail.MailMessage
     #Creating SMTP server object
      $smtp = new-object Net.Mail.SmtpClient($smtpServer)
     #Email structure 
      $msg.From = "no-reply@domain.com"
      $msg.ReplyTo = "no-reply@domain.com"
      $msg.subject = "subject"
      $msg.IsBodyHTML = $false
      $msg.body = "Hello world, testing relay"
     #Sending email