title: PowerShell - Send HTML file as Body of Email
body: <p>I am sorry for interrupting your daily work, but I need some help with the script below.
  The HTML report works fine, but it collects the data and puts them as HTML.  The problem is when I sent the HTML, it sends it as an attachment, not as Body.<br />
  I get the following error message</p>
  <pre><code>Send-MailMessage : Cannot validate argument on parameter 'Body'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
  At line:20 char:134
  + ... edtronic.com -Subject &quot;Folder Delition&quot; -Body $CoryReportHtml -BodyAs ...```
  </code></pre>
  <p>Could someone check what I am doing wrong?</p>
  <pre><code>#Time when the email is sent
  $emailTime = (Get-Date).ToString(&quot;MM/dd/yyyy&quot;)
  
  #Locate Folders older than 30 days
  $CoryReportHtml += Get-ChildItem &quot;\\Server01\XFER\Cory&quot; -Directory | 
      Sort LastWriteTime -Descending |
      Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} |
      Select-Object Name, LastWriteTime | 
      ConvertTo-Html -Head $Header -PreContent &quot;
          &lt;h2&gt;Folders older than 30 days&lt;/h2&gt; 
          &lt;body&gt;
              Folders were removed on - $emailTime
              &lt;br&gt;&lt;/br&gt;
              Location: \\Server01\XFER\Cory
          &lt;body&gt; 
          &lt;br&gt;&lt;/br&gt;&quot; |
      Out-File &quot;C:\APPS\Delete Folder - Cory\CoryHtmlReport.html&quot;
  
  
  Send-MailMessage -SmtpServer mail.company.com -to cubam1@company.com -from cubam1@company.com -Subject &quot;Folder Delition&quot; -Body $CoryReportHtml -BodyAsHtml = $true -Attachments &quot;C:\APPS\Delete Folder - Cory\CoryHtmlReport.html&quot;
  </code></pre>