簡體   English   中英

Send-MailMessage 正文中的 powershell 換行符

[英]powershell newline in Send-MailMessage body

如何讓 Send-MailMessage 在郵件正文中放置新行? 一個單獨的 PowerShell 腳本生成一些文件,我將內容讀入一個變量並將其作為正文發送,如下所示:

$fileContent = Get-Content -Path $file | Out-String
Send-MailMessage -BodyAsHtml -Body $fileContent -From $f -SmtpServer $s -To $t -Subject $s -Verbose

$fileContent 當前將具有

`r`n 

人物。 當您打開文件時,它有新行。 但是當我轉換為字符串並將電子郵件全部發送到一行時。 我試過像這樣替換:

$fileContent -replace  "`r`n","<br />"
$fileContent -replace  '`r`n','`r`n`r`n`r`n'

如果有人可以幫助我將不勝感激,謝謝!

這些是您可以嘗試的一些方法:

  1. 使用-BodyAsHtml開關
  2. 使用<br /> (break) html 標簽

例如:

powershell -ExecutionPolicy ByPass -Command Send-MailMessage -BodyAsHtml -SmtpServer 'myemail.server.com' -To 'Mr To <to@server.com>' -From 'Mr From <from@server.com>' -Subject 'Powershell BodyAsHtml' -Body 'I am just adding some random words here<br />and here also Line 2.<br />And also here Line 3.<br />and one more time Line 4.<br />EOF<br />'"

PowerShell 換行符是 `n(反引號-n)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM