0

I inherited a PS script that reads emails via EWS. I am trying to pickup the CC and BCC recipients.

I have this code.


    $carboncopy = ""
    $blindcarboncopy = ""

    foreach (Recipient in $MailItem.Recipients) {
    if (Recipient.Type -eq 1)
    {
    if (CCEmailAddress.length > 0) CCEmailAddress += ";";
    $carboncopy += recip.Address;
    }
    if (recip.Type -eq 2)
    {
    if (CCEmailAddress.length > 0) CCEmailAddress += ";";
    $blindcarboncopy += recip.Address;
    }
    } 

But it doesn't seem to work. I feel like I'm very close but probably not looking at the proper objects?

Thanks for any help, Alan

Big Al
  • 1
  • 1
  • 2
    You're missing a lot of $ in your variables. Also, can you tell us what "doesn't seem to work" means? What results are you seeing versus what you're expecting. – Mike Shepard Oct 30 '20 at 17:46
  • I get nothing in the carboncopy or blindcarboncopy variables even though they are in the email. – Big Al Oct 31 '20 at 19:12
  • It's may be related to the syntax errors you are talking about but I don't really know, which is why I am needing some help please. – Big Al Oct 31 '20 at 20:39
  • 1
    You need to post the whole code your using that doesn't look like EWS to me as EWS doesn't have a Recipients collection eg it has ToRecipients https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.emailmessage.torecipients?view=exchange-ews-api . Mapi has recipients so it maybe OOM or Redemption Also the bcc field will always be blank by design on any message in the Inbox (the only except is email in SentItems). – Glen Scales Nov 01 '20 at 22:34
  • The person that created the original PowerShell has stated that it's using EWS. Can someone give me the code to get cc and bcc for EWS? I tried finding code so it's extremely possible that my code is 100% wrong. I have not found an EWS solution that I could use so I tried the one I showed. Thanks – Big Al Nov 02 '20 at 23:08
  • If you post the original code we can help you fix that based on what you have posted it isn't EWS and it isn't even working Powershell code. If it Office365 its probably simpler to just rewrite it to use the Graph API. If you just want a sample of cc and bcc look at https://stackoverflow.com/questions/9875247/exchange-ews-get-bcc-recipients – Glen Scales Nov 02 '20 at 23:25

0 Answers0