SendMail Powershell - 嵌入.html文件

时间:2017-05-03 16:10:12

标签: powershell

我尝试使用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不熟悉,我非常感谢一种解决方法。

1 个答案:

答案 0 :(得分:4)

您需要将参数-BodyAsHTML添加到Send-MailMessage命令中。请参阅Get-Help Send-MailMessage