Powershell 使用html模板撰写新的outlook电子邮件
我的PowerShell脚本正在打开一个新的撰写outlook电子邮件窗口,并将正文设置为包含HTML的字符串,但它不会呈现HTML。有什么办法可以做到这一点吗Powershell 使用html模板撰写新的outlook电子邮件,powershell,Powershell,我的PowerShell脚本正在打开一个新的撰写outlook电子邮件窗口,并将正文设置为包含HTML的字符串,但它不会呈现HTML。有什么办法可以做到这一点吗 function Prepare_Outlook_email( $subject, $body, $to){ $ol = New-Object -comObject Outlook.Application $mail = $ol.CreateItem(0) $mail.Subject = $subject
function Prepare_Outlook_email( $subject, $body, $to){
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$mail.Subject = $subject
$mail | Get-Member
# $mail.IsBodyHTML = $true ###doesnt work
# $mail.HTMLBody = $body ###doesnt work the email format is already HTML
$mail.Body = $body
$mail.To = $to
$inspector = $mail.GetInspector
$inspector.Activate()
}
$body
是以下字符串
<html>
<head>
<title>test</title>
</head>
<body>
<table>
<tr>
<td>
Dear firstname,
Please visit <a href="www.google.com">here</a>
Kind Regards,
</td>
</tr>
</table>
</body>
</html>
测试
亲爱的名字,
请访问
亲切问候,,
关于如何解释HTML的任何想法。主要问题是我需要能够插入超链接。如果你能告诉我一种让超链接工作的不同方法,我可以忍受HTML不被解释
我发现这篇老帖子建议使用{HYPERLINK=“www.google.com”}
,但这似乎也不起作用
首先,只应设置
HTMLBody
属性。设置Body
将覆盖HTML。其次,您可能希望替换模板的某些部分(firstname
)。请参见下面的完整示例:
#replaceable parts marked using #
$body = @'
<html>
<head>
<title>test</title>
</head>
<body>
<table>
<tr>
<td>
Dear #firstname#,
Please visit <a href="www.google.com">here</a>
Kind Regards,
</td>
</tr>
<tr>
<td>
<a href="#link1#">Click here</a>
</td>
</tr>only
</table>
</body>
</html>
'@
$subject = 'Sample subject'
$parameters = @{
firstname='MyName';
link1='www.google.com'
}
#replace parts using dictionaryc as source
foreach ($pair in $parameters.GetEnumerator()) {
$body = $body -replace "#$($pair.Key)#",$pair.Value
}
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$mail.Subject = $subject
#set HTML body only
$mail.HTMLBody = $body
$inspector = $mail.GetInspector
$inspector.Activate()
#使用#
$body=@'
测试
亲爱的#名字#,
请访问
亲切问候,,
只有
'@
$subject='Sample subject'
$parameters=@{
firstname='MyName';
link1='www.google.com'
}
#使用dictionaryc作为源替换零件
foreach($parameters.GetEnumerator()中的pair){
$body=$body-替换“#$($pair.Key)#”,$pair.Value
}
$ol=新对象-comObject Outlook.Application
$mail=$ol.CreateItem(0)
$mail.Subject=$Subject
#仅设置HTML正文
$mail.HTMLBody=$body
$inspector=$mail.GetInspector
$inspector.Activate()
结果:
首先,只应设置
HTMLBody
属性。设置Body
将覆盖HTML。其次,您可能希望替换模板的某些部分(firstname
)。请参见下面的完整示例:
#replaceable parts marked using #
$body = @'
<html>
<head>
<title>test</title>
</head>
<body>
<table>
<tr>
<td>
Dear #firstname#,
Please visit <a href="www.google.com">here</a>
Kind Regards,
</td>
</tr>
<tr>
<td>
<a href="#link1#">Click here</a>
</td>
</tr>only
</table>
</body>
</html>
'@
$subject = 'Sample subject'
$parameters = @{
firstname='MyName';
link1='www.google.com'
}
#replace parts using dictionaryc as source
foreach ($pair in $parameters.GetEnumerator()) {
$body = $body -replace "#$($pair.Key)#",$pair.Value
}
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$mail.Subject = $subject
#set HTML body only
$mail.HTMLBody = $body
$inspector = $mail.GetInspector
$inspector.Activate()
#使用#
$body=@'
测试
亲爱的#名字#,
请访问
亲切问候,,
只有
'@
$subject='Sample subject'
$parameters=@{
firstname='MyName';
link1='www.google.com'
}
#使用dictionaryc作为源替换零件
foreach($parameters.GetEnumerator()中的pair){
$body=$body-替换“#$($pair.Key)#”,$pair.Value
}
$ol=新对象-comObject Outlook.Application
$mail=$ol.CreateItem(0)
$mail.Subject=$Subject
#仅设置HTML正文
$mail.HTMLBody=$body
$inspector=$mail.GetInspector
$inspector.Activate()
结果:
非常感谢!:)我以前测试过$mail.HTMLbody
;但当时我只是在试图呈现超链接的地方使用HTML。非常感谢!:)我以前测试过$mail.HTMLbody
;但当时我只是在试图呈现超链接的地方使用HTML。