Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Send-Notification () {
- param (
- [parameter(Mandatory = $true)]$body
- )
- [Byte[]] $key = (1..16)
- $params = Import-PowerShellDataFile "$PSScriptRoot\GMailConfiguration.psd1"
- $Today = Get-Date -Format "yyyy-MM-dd hh:mm"
- $params.add('body', $body)
- $subject = $params.Get_Item('subject') + ': ' + $Today
- $params.Set_Item('subject', $subject)
- #create an email
- $emailusername = $params.Get_Item('from')
- $recipientname = $params.Get_Item('to')
- $password = $params.Get_Item('securestring') | Out-String | ConvertTo-SecureString -Key $key
- $credential = New-Object System.Management.Automation.PsCredential($emailusername, $password)
- $params.Remove('securestring')
- try {
- Send-MailMessage @params -Credential $credential -UseSsl -ErrorAction Stop
- Write-Log "SOLR notification was sent to $recipientname"
- }
- Catch {
- Write-Log "Check email settings"
- throw "An error occured."
- }
- }
Add Comment
Please, Sign In to add comment