Scenario: You want to test the ability to send a test email that includes custom header information within the message. You plan on using this custom header information to perform a logical action based off the header value.
Scriptlet:
[string[]] $To = "steve@domain.com","chris@domain.com” [string] $Subject = "Testing for custom header info" [string] $Body = "testing 123 " [string] $SmtpHost = "smtp.domain.com" [string] $From = steve@domain.com $email = New-Object System.Net.Mail.MailMessage foreach($mailTo in $to) { $email.To.Add($mailTo) } $email.From = $from $email.Subject = $subject $email.Body = [string]::Format("{0}",$body); $email.Headers.Add("X-Test", "true"); $email.Headers.Add("X-Test2", "false"); ## Send the mail $client = New-Object System.Net.Mail.SmtpClient $smtpHost $client.UseDefaultCredentials = $true $client.Send($email)