如何使用PowerShell脚本将HTML文件内容嵌入电子邮件正文?

时间:2019-03-13 11:51:40

标签: html powershell email

我有一个HTML文件,其中包含CSS和HTML代码,如下所示。 我希望使用Powershell脚本将此内容嵌入电子邮件正文中。 下面是我的Powershell电子邮件脚本。

            $toUsers  = @('xxxx@microsoft.com','xxxx@microsoft.com')

            $fromUser = "xxxx@microsoft.com"
            $smtpServer = "xxx.XXX.corp.xxxx.com"
            #$ccUsers = "xxxx@microsoft.com"
            $msg = New-Object Net.Mail.MailMessage 
            $smtp = New-Object Net.Mail.SmtpClient($smtpServer) 
            $smtp.UseDefaultCredentials = $true 

            #$msg.Body =  $html
            $msg.Subject="c360 UX test run report"  -f (Get-Date -format "yyyy-MM-dd")
            foreach($toUser in $toUsers)
            {
                $msg.To.Add($toUser)
                write-host $toUser
            }
            $body = "<b>Build Number:- $(Build.BuildNumber)<br>"
            $body += "Branch Name:- $(Build.SourceBranch) </b> <br>"
            $body += "Product Name:- $env:PRODUCT_NAME <br>"
            $body +='<a href="\\scratch2\scratch\C360Report\ProtractorTestReport.html">Click here</a>'
            $msg.From = $fromUser
            #$msg.CC.Add($ccUsers)
            $msg.IsBodyHTML = $true
            $msg.Body = $body
            $attachmentObject = new-object Net.Mail.Attachment($(Get-ChildItem -Recurse -Path $(System.ArtifactsDirectory) -Filter 'Report.zip').FullName)
            $msg.Attachments.Add($attachmentObject)
            $msg.Priority="High"
            $smtp.Send($msg) 
            $smtp.Dispose()
            $msg.Dispose() 
            #Wait for a sec to let dispose complete.
            sleep 2`enter code here`

0 个答案:

没有答案