How to mail un bcc using powershell
To send an email with BCC (Blind Carbon Copy) using PowerShell, you can use the Send-MailMessage
cmdlet. Here's an example:
Send-MailMessage -From "your-email-address" -To "recipient-email-address" -Subject "Subject of the email" -Body "Body of the email" -Bcc "bcc-email-address1", "bcc-email-address2",...
Replace the placeholders with your actual email address, recipient's email address, subject, body, and BCC email addresses.
Here's a breakdown of the parameters:
-From
: The sender's email address.-To
: The recipient's email address.-Subject
: The subject of the email.-Body
: The body of the email.-Bcc
: A comma-separated list of email addresses to include in the BCC field.
You can also use the -SmtpServer
parameter to specify the SMTP server to use:
Send-MailMessage -From "your-email-address" -To "recipient-email-address" -Subject "Subject of the email" -Body "Body of the email" -Bcc "bcc-email-address1", "bcc-email-address2",... -SmtpServer "smtp.example.com"
Make sure to replace smtp.example.com
with the actual SMTP server address.
If you want to send the email using a specific port, you can use the -Port
parameter:
Send-MailMessage -From "your-email-address" -To "recipient-email-address" -Subject "Subject of the email" -Body "Body of the email" -Bcc "bcc-email-address1", "bcc-email-address2",... -SmtpServer "smtp.example.com" -Port 587
Replace 587
with the actual port number.
You can also use the -Credential
parameter to specify the credentials to use for authentication:
Send-MailMessage -From "your-email-address" -To "recipient-email-address" -Subject "Subject of the email" -Body "Body of the email" -Bcc "bcc-email-address1", "bcc-email-address2",... -SmtpServer "smtp.example.com" -Credential (Get-Credential)
This will prompt you to enter the username and password for the email account.
Note that the Send-MailMessage
cmdlet is available in PowerShell 3 and later versions. If you're using an earlier version, you may need to use a different method to send emails.