title: Powershell: Sending SMTP message to multiple recipients
body: <p>I'm trying to email multiple email address (entire code below for context) and keep getting an error message from powershell, not sure what i'm doing wrong, but the script is not passing the email address of each user from variable $expiredusers. </p>
  
  <p>Exception calling "Send" with "1" argument(s): "A recipient must be specified."
  At C:\expiredreminder.ps1:33 char:5
  +     $smtp.Send($msg)
  +     ~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : InvalidOperationException</p>
  
  <pre><code>Import-Module ActiveDirectory
  
  #Set the number of days within expiration.  This will start to send the email x number of days before 
  it is expired.
  $DaysWithinExpiration = 7
  
  #Set the days where the password is already expired and needs to change.
  $MaxPwdAge   = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days
  $expiredDate = (Get-Date).addDays(-$MaxPwdAge)
  
  #Set the number of days until you would like to begin notifying the users.
  $emailDate = (Get-Date).addDays(-($MaxPwdAge - $DaysWithinExpiration))
  
  #Filters for all users who's password is within $date of expiration.
  $ExpiredUsers = Get-ADUser -Filter {(PasswordLastSet -lt $emailDate) -and (PasswordLastSet -gt 
  $expiredDate) -and (PasswordNeverExpires -eq $false) -and (Enabled -eq $true)} -Properties 
  PasswordNeverExpires, PasswordLastSet, Mail | select samaccountname, PasswordLastSet, @{name = 
  "DaysUntilExpired"; Expression = {$_.PasswordLastSet - $ExpiredDate | select -ExpandProperty Days}}, 
  @{name = "EmailAddress"; Expression = {$_.mail}} | Sort-Object PasswordLastSet
  
  
  Start-Sleep 5
  
  Foreach ($User in $ExpiredUsers) {
  
  $msg = new-object Net.Mail.MailMessage
  
  
  $msg.From = "noreply@hdomain.com"
  $msg.To.Add($User.EmailAddress)
  $msg.Subject = "blah blah subject"
  $msg.Body = "blah blah message text"
  
  
  
  $smtpServer = "smtpserver.domain.com"
  $smtp = new-object Net.Mail.SmtpClient($smtpServer)
  $smtp.Send($msg)
  
  }
  </code></pre>