我有一个脚本,用于查找文件夹以进行更新,如果有任何更新,则发送电子邮件。如何将电子邮件的正文更改或转换为URL或HTML链接而不是文本?
以下路径和服务器是示例。
这是我的脚本:
Param (
[string]$Path = "\\Desktop\Myfolder\status updates",
[string]$SMTPServer = "smtp.myfolder.com",
[string]$From = "Admin@me.com",
[string]$To = "Admin@me.com",
[string]$CC = "Admin@me.com",
[string]$Subject = "New Status Report"
)
$SMTPMessage = @{
To = $To
Cc = $cc
From = $From
Subject = "$Subject"
Smtpserver = $SMTPServer
}
$File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-10) }
If ($File)
{ $SMTPBody = "`The following files have recently been added/changed. Please copy and paste the following link to Windows Explorer:`n`n"
$File | ForEach { $SMTPBody += "$($_.FullName)`n" }
Send-MailMessage @SMTPMessage -Body $SMTPBody
最佳答案
PowerShell提供了一个Convert-ToHTML
cmdlet,非常适合您的需求。
只需将内容$SMTPBody
传送到其中即可。您甚至可以应用CSS文件来使电子邮件看起来更好一点。
$HTMLBody = ConvertTo-HTML -body $SMTPBody -CSSUri http://www.csszengarden.com/examples/style.css
然后在您的电子邮件中引用
$HTMLBody
。天空是CSS的极限。如果您想了解更多信息,请I covered this topic in a blog post。这是我们可以创建的示例。
在此示例中,我们使用
-Pre
和-Post
参数在表上方和下方添加内容。通过使用Convert-ToHTML
属性将对象通过管道传递到-As Table
中来创建表。仅包含四个参数的此cmdlet可以创建值得输出的网页!
关于html - Powershell将主体转换为HTML主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43854051/