Situatie
This example sends bulk email to users.
Solutie
Pasi de urmat
Once we have our input file created, we can use the magic of PowerShell to generate our notifications using this data. The following script imports the .CSV file and generates a simple email notification that is then sent to everyone in the list:
2. [powershell]
# Function to create report email
function SendNotification
$Msg = New-Object Net.Mail.MailMessage
$Smtp = New-Object Net.Mail.SmtpClient($ExchangeServer)
$Msg.From = $FromAddress
$Msg.To.Add($ToAddress)
$Msg.Subject = “Announcement: Lorem Ipsum available.”
$Msg.Body = $EmailBody
$Msg.IsBodyHTML = $true
$Smtp.Send($Msg)
}
# Define local Exchange server info for message relay. Ensure that any servers running this script have permission to relay.
$ExchangeServer = “yourexchange.domain.com”
$FromAddress = “mail <mail@domain.com>”
# Import user list and information from .CSV file
$Users = Import-Csv UserList.csv
# Send notification to each user in the list
Foreach ($User in $Users) {
$ToAddress = $User.Email
$Name = $User.FirstName
$EmailBody = @”
Dear $Name,
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don’t look even slightly believable.
“@
Write-Host “Sending notification to $Name ($ToAddress)”
SendNotification
}
[/powershell]
Leave A Comment?