我想获取.md文件的内容,并将其显示在生成的Outlook电子邮件正文中。我可以生成刚刚找到的电子邮件,但正文给出以下错误,但我尚未找到解决方法。
错误:
The object does not support this method.
At line:6 char:1
+ $new.HTMLBody = $a
+ ~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
码:
$out= New-Object -comObject Outlook.Application
# $sign= Get-Content "C:\Users\Roaming\Microsoft\Signatures\sign.htm"
$recipient= "[email protected]"
$new= $out.CreateItem(0)
$new.Subject = "Meeting details"
$a = Get-Content -Path "c:\temp\file.md"
$new.HTMLBody = $a
$new.Recipients.Add($recipient)
$new.save()
# $new.HTMLBody += $sign
$display= $new.GetInspector
$display.Display()
要解决发布的错误消息,您需要将文件读取为字符串而不是字符串数组。原因是因为$new.Body
期望一个字符串。默认情况下,Get-Content
返回一个数组,文件的每一行都是该数组的元素。您可以使用-Raw
开关更改此行为,该开关会将内容作为一个字符串读取。
$a = Get-Content -Path "c:\temp\file.md" -Raw
如果-Raw
开关更改了换行符格式,则始终可以将默认Get-Content
数组与所选的换行符结合在一起。
$a = Get-Content -Path "c:\temp\file.md"
$new.HTMLBody = $a -join "`r`n"
您可以使用GetType()
PowerShell对象可用的方法查看原始代码中的类型差异。
$a.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
$new.Body.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句