01-18-2009
Downloads: 594
File size: 1.7kB
Views: 6,284
Embed
 |
Send SMTP Mail Message with BCC |
- <
- .SYNOPSIS
- Send mail to BCC using PowerShell
- .DESCRIPTION
- This script is a re-developed MSDN Sample using PowerShell. It creates
- an email message then sends it with a BCC.
- .NOTES
- File Name : Send-BCCMail.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Original Sample Posted to
- http://www.pshscripts.blospot.com
- MSDN Sample and details at:
- http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddresscollection.aspx
- .EXAMPLE
- PS C:\foo> .\Send-BCCMail.ps1
- Sending an e-mail message to The PowerShell Doctor and "Thomas Lee" <tfl@reskit.net>
-
-
-
-
-
-
-
- $from = New-Object system.net.Mail.MailAddress "tfl@cookham.net", "Thomas Lee"
- $to = new-object system.net.mail.mailaddress "doctordns@gmail.com", "The PowerShell Doctor"
- $bcc = New-Object system.Net.Mail.mailaddress "tfl@reskit.net", "Thomas Lee"
- $message = New-Object system.Net.Mail.MailMessage $from, $to
-
-
- $message.Subject = "Using the SmtpClient class and PowerShell."
- $message.Body = "Using this feature, you can send an e-mail message from an"
- $message.Body += "application very easily. `nEven better, you do it with PowerShell!"
-
-
- $message.Bcc.Add($bcc);
-
-
- $server = "localhost"
- $client = New-Object system.Net.Mail.SmtpClient $server
- $client.Credentials = [system.Net.CredentialCache]::DefaultNetworkCredentials
- "Sending an e-mail message to {0} and {1}" -f $to.DisplayName, $message.Bcc.ToString()
-
-
- try {
- $client.Send($message);
- }
- catch {
- "Exception caught in CreateBccTestMessage(): {0}" -f $Error[0]
- }
This script creates an SMTP Mail message, with To;, From: and BCC:, then sends it using a local SMTP Server.