我正在尝试使用 Powershell 输出包含一些前/后内容的表格,然后通过电子邮件发送,但前/后内容在电子邮件中显示为“System.String []”。其余的内容看起来都很好,如果我将 HTML 字符串输出到控制台,一切看起来都很好。
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
$Content = get-process | Select ProcessName,Id
$headerString = "<table><caption> Foo. </caption>"
$footerString = "</table>"
$MyReport = $Content | ConvertTo-Html -fragment -precontent $headerString -postcontent $footerString
send-SMTPmail "my Email" "from email" "My Report Title" "My SMTP SERVER" $MyReport
在我的电子邮件中显示为:
System.String[]
ProcessName Id
... ...
System.String[]
做一个输出文件,然后一个调用项与发送电子邮件的结果相同......