我知道有多个博客教授如何使用 html 和 css 格式发送电子邮件,但在 Azure Runbooks 的 PowerShell 工作流中似乎没有任何效果。
我想在电子邮件中发送计划的 Azure Runbook 的状态,该 Runbook 处理 Azure 分析表格模型,表格包含所有详细信息。
截至目前,我正在尝试发送带有基本边框的电子邮件。到目前为止,我已经使用了这个脚本:
<#
This PowerShell script was automatically converted to PowerShell Workflow so it can be run as a runbook.
Specific changes that have been made are marked with a comment starting with “Converter:”
#>
workflow TablePS {
inlineScript {
# Create a DataTable
$table = New-Object system.Data.DataTable "TestTable"
$col1 = New-Object system.Data.DataColumn Name,([string])
$col2 = New-Object system.Data.DataColumn Dept,([string])
$table.columns.add($col1)
$table.columns.add($col2)
# Add content to the DataTable
$row = $table.NewRow()
$row.Name = "John"
$row.Dept = "Physics"
$table.Rows.Add($row)
$row = $table.NewRow()
$row.Name = "Susan"
$row.Dept = "English"
$table.Rows.Add($row)
# Create an HTML version of the DataTable
$html = "<table><tr><td>Name</td><td>Dept</td></tr>"
foreach ($row in $table.Rows)
{
$html += "<tr><td>" + $row[0] + "</td><td>" + $row[1] + "</td></tr>"
}
$html += "</table>"
$MyCredential = "DevCreds"
$Cred = Get-AutomationPSCredential -Name $MyCredential
$CredUsername = $Cred.UserName
$CredPassword = $Cred.GetNetworkCredential().Password
# Send the email
$smtpserver = "smtp.office365.com"
$from = "Prakhar.Saxena@Eriks.com"
$to = "Prakhar.Saxena@Eriks.com"
$subject = "test"
$body = "Hi there,<br />Here is a table:<br /><br />" + $html
Send-MailMessage -smtpserver $smtpserver -UseSsl -Port 587 -from $from -to $to -subject $subject -body $body -Credential $Cred -bodyashtml
}
}
但这对我没有帮助。我得到一个没有任何边框的表格类型格式。你们能帮我解决这个问题吗?PFB: 此处的图像片段