我尝试使用Powershell中的SendMail将.html文件(外部生成)中的HTML表格嵌入到电子邮件中。我的代码如下:
$userid = 'xxx@workdomain.com'
$creds = Get-Credential $userid
$port = 587
$smtp = "smtp.office365.com"
$to = "otherpeople@workdomain.com"
$from = $userid
$subject = "FX summary report"
$body = Get-Content ("C:\Users\xxx\Documents\R\newtrend.table.html")
$body = $body | out-string
Send-MailMessage -To $to -Subject $subject -Body $body -UseSsl -Port $port -SmtpServer $smtp -From $from -Credential $creds
但是,这并没有嵌入html代码,而是将html写成文本。我的电子邮件如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
....
我对PowerShell不熟悉,我非常感谢一种解决方法。