Share via


Sending email to multiple users in BCC field

Question

Friday, June 14, 2019 7:50 PM

I'm trying to use PowerShell to send an Outlook email to a list of email addresses, but I would like them all to be BCC'd so none of the users see that other individuals are being sent the email. The code below works to send the email to 2 users, but I'm having trouble adapting this to BCC the emails rather than include them all in the To field. Any assistance would be greatly appreciated!

$ol = New-Object -comObject Outlook.Application 
$ns = $ol.GetNameSpace("MAPI")
$mail = $ol.CreateItem(0)
[String[]]$Recipient = '[email protected]','[email protected]'
$Recipient | % {$mail.recipients.add($_)}
$ndatetime = Get-Date -Format g
$Mail.Subject = 'Testing' 
$Mail.Body = "Testing"
$Mail.send()

All replies (7)

Tuesday, June 18, 2019 5:38 PM ✅Answered

The suggested solution didn't work exactly as written for me, but I was able to adapt it. The following code worked for me:

(get-credential).password | ConvertFrom-SecureString | set-content "C:\documents\password.txt"

$password = Get-Content "C:\documents\password.txt" | ConvertTo-SecureString 

$message = New-Object System.Net.Mail.MailMessage
$message.Subject = "Testing"
$message.Body = "Testing"
[String[]]$BCC = '[email protected]','[email protected]'
$BCC | % {$message.BCC.add($_)}
$message.From = "[email protected]" 

$smtp = New-Object System.Net.Mail.SmtpClient('smtp-mail.outlook.com','587');
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential('[email protected]', $password);
$smtp.send($message)

Friday, June 14, 2019 8:23 PM

https://devspoint.wordpress.com/2011/12/08/send-email-using-powershell/


Friday, June 14, 2019 8:23 PM

Just add the list to the BCC field.  There is no other way.

\(ツ)_/


Friday, June 14, 2019 8:41 PM

Can you please help me with the syntax of adding this BCC field? 


Friday, June 14, 2019 8:52 PM

it is exacrly like the "To" field.

\(ツ)_/


Tuesday, June 18, 2019 9:13 AM

Hi,

Was your issue resolved?

If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

If no, please reply and tell us the current situation in order to provide further help.

Best Regards,

Lee

Just do it.


Tuesday, June 18, 2019 5:45 PM

why use an old PS1 method when you can just use the correct Net PowerShell command "Send-MailMessage".

$mailprops = @{
    To = '[email protected]'
    From = "[email protected]"
    Subject = "Testing"
    Body = "Testing"
    BCC = '[email protected]', '[email protected]'
    SMTPServer = 'smtp-mail.outlook.com'
    Port = 587
    UseSSL = $true
    Credentials = New-Object System.Net.NetworkCredential('[email protected]', $password)
}
Send-MailMessage @mailprops

help send-mailmessage -online

\(ツ)_/