繁体   English   中英

Azure PowerBook使用Powershell工作流在表中发送电子邮件

[英]azure runbook send email in table using powershell workflow

我知道有多个博客教我们如何使用html和css格式发送电子邮件,但是Azure Runbooks的PowerShell Workflow中似乎没有任何作用。

我想发送已安排的Azure 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: 此处的图片片段

发送电子邮件时,请记住您的CSS样式应该是内联的,以支持大多数邮件客户端。

# Define your styles.
$borderWidth = "1px"
$borderStyle = "solid"
$borderColor = "rgba(255, 0, 0, 1)"
$borderStyles = @("border-width: $borderWidth;", "border-style: $borderStyle;", "border-color: $borderColor;")
$styleAttribute = " style=`"$borderStyles`""

然后,只需将$styleAttribute添加到要应用它的任何位置。

# Create an HTML version of the DataTable
$html = "<table $styleAttribute><tr><td $styleAttribute>Name</td><td $styleAttribute>Dept</td></tr>"
foreach ($row in $table.Rows) { 
    $html += "<tr><td $styleAttribute>" + $row[0] + "</td><td $styleAttribute>" + $row[1] + "</td></tr>"
}
$html += "</table>"

使用CSS,直到获得所需的内容。 您将需要为tabletd元素添加样式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM