【问题标题】:powershell to change existing email from text format to html body formatpowershell 将现有电子邮件从文本格式更改为 html 正文格式
【发布时间】: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.Bodysystem.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


【解决方案1】:

您只需要设置 MailItem 类的BodyFormat 属性。无需转换现有正文并设置HTMLBody 属性。

如果您对正文的 HTML 标记进行任何修改,请确保您得到格式良好的 HTML 标记。

【讨论】:

  • 谢谢尤金,这对我有用。有时你需要简单地思考:)
猜你喜欢
  • 1970-01-01
  • 2011-06-02
  • 2020-05-09
  • 1970-01-01
  • 2013-11-11
  • 1970-01-01
  • 2016-04-12
  • 2019-06-22
  • 2016-02-23
相关资源
最近更新 更多