[英]powershell newline in Send-MailMessage body
how do I get Send-MailMessage to put new lines in the body of the mail?如何让 Send-MailMessage 在邮件正文中放置新行? A separate PowerShell script generates some files, I read the content into a variable and send it as the body like so:
一个单独的 PowerShell 脚本生成一些文件,我将内容读入一个变量并将其作为正文发送,如下所示:
$fileContent = Get-Content -Path $file | Out-String
Send-MailMessage -BodyAsHtml -Body $fileContent -From $f -SmtpServer $s -To $t -Subject $s -Verbose
$fileContent would currently have the $fileContent 当前将具有
`r`n
characters.人物。 When you open the file it has new lines.
当您打开文件时,它有新行。 But when I convert to string and send the email its all on one line.
但是当我转换为字符串并将电子邮件全部发送到一行时。 I have tried replacing like this:
我试过像这样替换:
$fileContent -replace "`r`n","<br />"
$fileContent -replace '`r`n','`r`n`r`n`r`n'
If anyone can help I would be very appreciative, thanks!如果有人可以帮助我将不胜感激,谢谢!
These are some of the approaches you can try:这些是您可以尝试的一些方法:
-BodyAsHtml
switch-BodyAsHtml
开关<br />
(break) html tag<br />
(break) html 标签for example:例如:
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 />'"
The PowerShell newline indicator is `n (backtick-n) PowerShell 换行符是 `n(反引号-n)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.