Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions CMPackager.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1765,13 +1765,31 @@ Combines the output from Get-ChildItem with the Get-ExtensionAttribute function,
Function Send-EmailMessage {
Add-LogContent "Sending Email"
$Global:EmailBody += "`n`nThis message was automatically generated"
Try {
Send-MailMessage -To $EmailTo -Subject $EmailSubject -From $EmailFrom -Body $Global:EmailBody -SmtpServer $EmailServer -ErrorAction Stop
}
Catch {

$msg = $null

try {
$msg = New-Object Net.Mail.MailMessage
$smtp = New-Object Net.Mail.SmtpClient($EmailServer)

$msg.From = $EmailFrom
$EmailTo | ForEach-Object {
$msg.To.Add($_)
}
$msg.Subject = $EmailSubject
$msg.Body = $Global:EmailBody

$smtp.Send($msg)
Add-LogContent "Email Sent to $EmailTo"
} catch {
$ErrorMessage = $_.Exception.Message
Add-LogContent "ERROR: Sending Email Failed!"
Add-LogContent "ERROR: $ErrorMessage"
} finally {
$smtp.Dispose()
if ($msg) {
$msg.Dispose()
}
}
}

Expand Down