【发布时间】:2018-06-15 13:05:50
【问题描述】:
我有将 html 添加到 Outlook 中收到的 html 格式电子邮件的工作代码。这很好用,现在想将其扩展到“纯文本”电子邮件。
我的计划是将 (text)body 的内容复制到 htmlbody 以将邮件转换为 html 格式,但不知何故,生成的电子邮件总是空的。 Write-Output 看起来不错。
$textcontent = $item.Body.ToString()
Write-Output $textcontent
$item.HTMLBody = $textcontent | ConvertTo-Html -Head $style
$item.Save()
所以看起来根本问题是$item.Body 是system.object 类型而不是string 并且似乎没有正确转换?
我可以尝试任何想法吗?
【问题讨论】:
-
如果你在保存之前设置
$item.IsBodyHtml = $true会发生什么(甚至在你放入HTMLBody之前?? -
感谢@Theo 的评论,很遗憾我收到以下错误消息:
Exception setting "IsBodyHtml": "The property 'IsBodyHtml' cannot be found on this object. Verify that the property exists and can be set."At 1:57 char:4 + $item.IsBodyHtml = $true + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : ExceptionWhenSetting -
好的,那么
$item到底是什么类型的对象,它有什么属性/方法? -
我试过
$item.BodyFormat = 2但也没有效果 -
好的,所以它显然不是 MailMessage 类型的对象,但是......它是什么?你需要做一个
$item | Get-Member或$item | Select-Object -Property *来弄清楚你可以用它做什么..
标签: powershell outlook