【问题标题】:Add multiline body to powershell email将多行正文添加到 PowerShell 电子邮件
【发布时间】:2020-06-20 02:29:36
【问题描述】:

我正在尝试在正文中添加多行,但找不到修复方法。我试图用 html 来做,但我不知道如何......

$Email       = "x"
$Internal    = "x"
$Subject     = "New"
$Body        = "Sending new files. Cheers!"

[array]$attachments = Get-ChildItem "\\ip\ftp$\new\Fac" *.pdf

if ([array]$attachments -eq $null) {
}

else {

$Msg = @{
    to          = $Email
    cc          = $Internal
    from        = "to"
    Body        = $Body
    subject     = "$Subject"
    smtpserver  = "server"
    BodyAsHtml  = $True
    Attachments = $attachments.fullname
}

Send-MailMessage @Msg

}

【问题讨论】:

标签: powershell


【解决方案1】:

如果您想要多行字符串文字,请使用 here-strings:

$Body = @'
Multiple
lines

go

here
'@

您还可以使用 -join 运算符从多个单独的字符串构造多行字符串:

$Body = 'Line1','Line2','Line3' -join [Environment]::NewLine

但既然你想要 HTML,最好加入 <br /> 代替:

$Body = 'Line1','Line2','Line3' -join '<br />'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    • 2017-11-06
    • 2011-03-04
    相关资源
    最近更新 更多