diff --git a/tools/TestFx/Live/SendLiveTestReport.ps1 b/tools/TestFx/Live/SendLiveTestReport.ps1
index ff08644249fd..4a95da5fa38b 100644
--- a/tools/TestFx/Live/SendLiveTestReport.ps1
+++ b/tools/TestFx/Live/SendLiveTestReport.ps1
@@ -86,10 +86,10 @@ $summarySection = @"
"@
if ($errorsArr.Count -gt 0) {
- $emailBody = $errorsArr | Sort-Object OSVersion, PSVersion, Module, Name | ConvertTo-Html -Property OSVersion, PSVersion, Module, Name, Exception, RetryException -Head $css -Title "Azure PowerShell Live Test Report" -PreContent "$summarySection
Live Test Error Details
"
+ $emailContent = $errorsArr | Sort-Object OSVersion, PSVersion, Module, Name | ConvertTo-Html -Property OSVersion, PSVersion, Module, Name, Exception, RetryException -Head $css -Title "Azure PowerShell Live Test Report" -PreContent "$summarySectionLive Test Error Details
"
}
else {
- $emailBody = "$css$summarySectionNo live test errors reported. Please check the overall status from Azure pipeline.
"
+ $emailContent = "$css$summarySectionNo live test errors reported. Please check the overall status from Azure pipeline.
"
}
-Send-EmailServiceMail -To "${env:EMAILTO}" -Subject $emailSubject -Body $emailBody
+Send-EmailServiceMail -To "${env:EMAILTO}" -Subject $emailSubject -Content $emailContent -IsHtml
diff --git a/tools/TestFx/Utilities/EmailServiceUtility.psm1 b/tools/TestFx/Utilities/EmailServiceUtility.psm1
index 63d357cf54de..27e705b7a78c 100644
--- a/tools/TestFx/Utilities/EmailServiceUtility.psm1
+++ b/tools/TestFx/Utilities/EmailServiceUtility.psm1
@@ -44,14 +44,39 @@ function Send-EmailServiceMail {
[string] $Subject,
[Parameter(Mandatory)]
- $Body
+ [string] $Content,
+
+ [Parameter()]
+ [switch] $IsHtml
)
$emailClient = [Azure.Communication.Email.EmailClient]::new($EmailServiceConnectionString)
- Write-Host "Sending email..."
- $emailClient.SendAsync([Azure.WaitUntil]::Completed, $EmailFrom, $To, $Subject, $Body).GetAwaiter().GetResult()
- Write-Host "Finished sending email."
+ $emailContent = [Azure.Communication.Email.EmailContent]::new($Subject)
+ if ($IsHtml.IsPresent) {
+ $emailContent.Html = $Content
+ }
+ else {
+ $emailContent.PlainText = $Content
+ }
+
+ $emailTo = $To.Split(";", [StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object {
+ [Azure.Communication.Email.EmailAddress]::new($_)
+ }
+ $emailRecipients = [Azure.Communication.Email.EmailRecipients]::new([System.Collections.Generic.List[Azure.Communication.Email.EmailAddress]]$emailTo)
+
+ $emailMessage = [Azure.Communication.Email.EmailMessage]::new($EmailFrom, $emailRecipients, $emailContent)
+
+ Write-Host "##[section]Start sending email notification."
+
+ try {
+ $emailClient.Send([Azure.WaitUntil]::Completed, $emailMessage)
+ }
+ catch {
+ Write-Error "Failed to send email notification with error message: $($_.Exception.Message)."
+ }
+
+ Write-Host "##[section]Finished sending email notification."
}
InitializeEmailServicePackages