Private/Send-ALMailNotification.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function Send-ALMailNotification
{
    param
    (
        [Parameter(Mandatory = $true)]
        [System.String]
        $Activity,

        [Parameter(Mandatory = $true)]
        [System.String]
        $Message
    )

    $lab = Get-Lab

    $body = @"
    Dear recipient,

    Lab $($lab.Name) on $($Lab.DefaultVirtualizationEngine)logged activity "$Activity" with the following message:

    $Message
"@


    $mailParameters = @{
        SmtpServer =  Get-LabConfigurationItem -Name Notifications.NotificationProviders.Mail.SmtpServer
        From = Get-LabConfigurationItem -Name Notifications.NotificationProviders.Mail.From
        CC = Get-LabConfigurationItem -Name Notifications.NotificationProviders.Mail.CC
        To = Get-LabConfigurationItem -Name Notifications.NotificationProviders.Mail.To
        Priority = Get-LabConfigurationItem -Name Notifications.NotificationProviders.Mail.Priority
        Port = Get-LabConfigurationItem -Name Notifications.NotificationProviders.Mail.Port
        Body = $body
        Subject = "AutomatedLab notification: $($lab.Name) $Activity"
    }


    Send-MailMessage @mailParameters
}