title: Send HTML Formatted Email to Multiple Recipients with Powershell
body: <p>I have a PowerShell function which I would like to expand on, but have hit a roadblock with a couple of features.</p>
  
  <p><strong>End goal</strong>: Send a html formatted email via SMTP with Windows PowerShell to multiple recipients.</p>
  
  <p><strong>Criteria</strong>:</p>
  
  <ol>
  <li>The user must specify either a CSV path to import the relevant variables, or;</li>
  <li>The user must specify a these variables as parameters.</li>
  <li>The html file must be external to the script and must contain powershell variables.</li>
  </ol>
  
  <p><strong>The function so far</strong>:</p>
  
  <pre><code>Function Send-HTMLEmail
  {
      [CmdletBinding()]
      Param
      (
          [Parameter(ValueFromPipelineByPropertyName=$true)][string]$smtpRecipientAddress,
          [Parameter(ValueFromPipelineByPropertyName=$true)][string]$smtpSubject, 
          [Parameter(ValueFromPipelineByPropertyName=$true)][string]$smtpFromAddress = 'info@domain.com', 
          [Parameter(ValueFromPipelineByPropertyName=$true)][string]$smtpServer = 'exchserver', 
          [Parameter(ValueFromPipelineByPropertyName=$true)][string]$htmlFilePath,
          [Parameter(ValueFromPipelineByPropertyName=$true)][string]$CSVFile
      )
      $smtpClient = new-object system.net.mail.smtpClient 
      $mailMessage = New-Object system.net.mail.mailmessage 
      $SmtpClient.Host = $smtpServer 
      $mailMessage.From = $smtpFromAddress 
      $mailMessage.To.add($smtpRecipientAddress)
      $mailMessage.Subject = $smtpSubject
      $mailMessage.IsBodyHtml = $true
      $mailMessage.Body = $emailTemplate
      $smtpClient.Send($mailMessage) 
  }
  </code></pre>
  
  <ol>
  <li><p>As you can see, the function has no mandatory parameters. This is easy enough to add, but I'm not sure how to specify either the CSVFile parameter as mandatory or all the others.</p></li>
  <li><p>Below is a rough example of what the html should look like. How can this be imported and the PowerShell variables initialised? (note that the variables in the below email are to be imported from another script, this is unrelated):</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;style&gt;
  body {
  background-color: #DEE8F1;
  }
  p.normal {
  font-family: "Calibri";
  color: black;
  font-size: 13px;
  }
  p.normal em{
  font-family: "Calibri";
  color: black;
  font-size: 13px;
  font-weight: bold;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p class="normal"&gt;&lt;em&gt;$($user.Name)&lt;/em&gt;,&lt;br /&gt;&lt;br /&gt; 
  Your password will expire in &lt;em&gt;$($userTable.DaysTillExpiry)&lt;/em&gt; days
  on &lt;em&gt;$($userTable.ExpiryDate)&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;
  Your domain password is required for Computer Login, remote VPN, 
  and Email Access.&lt;br /&gt;&lt;br /&gt;
  To change your password, press CTRL-ALT-DEL and choose Change Password.&lt;br /&gt;&lt;br&gt;
  For your password to be valid it must be 8 or more characters long and&lt;br /&gt;
  contain a mix of the following properties:&lt;br /&gt;&lt;br /&gt;
  uppercase letters (A-Z)&lt;br /&gt;
  lowercase letters (a-z)&lt;br /&gt;
  numbers (0-9)&lt;br /&gt;&lt;br /&gt;
  Regards,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;em&gt;IT Department&lt;/em&gt; &lt;br /&gt;
  Ph: +xx xxxx xxxx &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;br /&gt;&lt;/h1&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre></li>
  </ol>
  
  <p>Any help would be greatly appreciated!</p>