title: powershell - How to send outlook mail with content read from excel (csv)
body: <p>can anyone give me an example about how to How to send outlook mail with content read from excel (csv)?</p>
  
  <p>It seems to work for txt but not for excel</p>
  
  <pre><code>$o = New-Object -com Outlook.Application
  $mail = $o.CreateItem(0)
  $yesterday = (get-date).AddDays(-1).ToString('MMM dd, yyyy')
  
  $mail.subject = "Missing/Empty Files"
  
  $mail.Attachments.Add("I:\BadFileReport_20170711_0103.csv")
  
  $mail.HTMLBody += "&lt;span style='font-family:Courier New;font-size:12pt'&gt;"  
  
  $mail.HTMLbody = $mail.HTMLBody + "&lt;B&gt;Please check missing/empty files for yesterday&lt;/B&gt;&lt;br&gt;&lt;br&gt;" 
  
  $file1 = import-csv I:\BadFileReport_20170711_0103.csv
  
  
  foreach ($line in $file1)
  {
      $mail.HTMLbody = $mail.HTMLbody  + $line   
  }
  
  $mail.HTMLbody = $mail.HTMLbody + $title2 + "&lt;br&gt;"
  
  
  
  
  $signature = "&lt;br&gt;Regards,&lt;br&gt;"
  
  $mail.HTMLbody = $mail.HTMLbody + $signature
  
  
  
  $mail.To = "12345@imcnam.ssmb.com"
  
  write-host "mail sent"
  
  $mail.save()
  </code></pre>
  
  <p>output looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/piRft.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/piRft.png" alt="enter image description here"></a></p>