none
Sending email to multiple users in BCC field RRS feed

  • Question

  • 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 = 'abc@xxx.com','xyz@xxx.com'
    $Recipient | % {$mail.recipients.add($_)}
    $ndatetime = Get-Date -Format g
    $Mail.Subject = 'Testing' 
    $Mail.Body = "Testing"
    $Mail.send()


    • Edited by asomers21 Friday, June 14, 2019 8:22 PM
    Friday, June 14, 2019 7:50 PM

Answers

  • 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 = 'abc@xxx.com','xyz@xxx.com'
    $BCC | % {$message.BCC.add($_)}
    $message.From = "yyy@xxx.com" 
    
    $smtp = New-Object System.Net.Mail.SmtpClient('smtp-mail.outlook.com','587');
    $smtp.EnableSSL = $true
    $smtp.Credentials = New-Object System.Net.NetworkCredential('yyy@xxx.com', $password);
    $smtp.send($message)


    • Marked as answer by asomers21 Tuesday, June 18, 2019 5:38 PM
    • Edited by asomers21 Tuesday, June 18, 2019 5:38 PM
    Tuesday, June 18, 2019 5:38 PM

All replies

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


    \_(ツ)_/

    Friday, June 14, 2019 8:23 PM
    Moderator
  • Can you please help me with the syntax of adding this BCC field? 
    Friday, June 14, 2019 8:41 PM
  • it is exacrly like the "To" field.


    \_(ツ)_/

    Friday, June 14, 2019 8:52 PM
    Moderator
  • 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 9:13 AM
    Moderator
  • 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 = 'abc@xxx.com','xyz@xxx.com'
    $BCC | % {$message.BCC.add($_)}
    $message.From = "yyy@xxx.com" 
    
    $smtp = New-Object System.Net.Mail.SmtpClient('smtp-mail.outlook.com','587');
    $smtp.EnableSSL = $true
    $smtp.Credentials = New-Object System.Net.NetworkCredential('yyy@xxx.com', $password);
    $smtp.send($message)


    • Marked as answer by asomers21 Tuesday, June 18, 2019 5:38 PM
    • Edited by asomers21 Tuesday, June 18, 2019 5:38 PM
    Tuesday, June 18, 2019 5:38 PM
  • why use an old PS1 method when you can just use the correct Net PowerShell command "Send-MailMessage".

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

    help send-mailmessage -online


    \_(ツ)_/


    Tuesday, June 18, 2019 5:45 PM
    Moderator