1

When trying to read the .msg file in .Net using the dll Microsoft.Office.Interop.Outlook Version 15.0.0.0 facing the issue in reading large recipients.

Scenarios:

  1. If the .msg file contains less recipients e.g less than 300 then value in To property shows actual recipients.
  2. If the .msg file has more than 300 recipients then To property of MailItem object is getting null shows no blank.

Does the library have any limitations for the recipients to read or anything I am missing to handle more recipients?

    Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
    Microsoft.Office.Interop.Outlook.Application();

    var item = app.Session.OpenSharedItem(msgfilepath) as Microsoft.Office.Interop.Outlook.MailItem;
    string message = item.Body
    string recipients = item.To   
   //This To property gets null in case file has large recipients list.
HackSlash
  • 4,944
  • 2
  • 18
  • 44
Milind
  • 437
  • 2
  • 9
  • 23
  • 1
    Try looping over the Recipients collection: https://stackoverflow.com/questions/28986306/get-item-recipient-with-outlook-vba – Tim Williams Jun 07 '19 at 15:11
  • @TimWilliams. Yes try with Recipients property and getting the collection of recipients but my actual problem is not getting it in `To` property for large recipients only, – Milind Jun 11 '19 at 08:17
  • 1
    If the number of recipients is large then you *need* to loop over the Recipients collection. That's just how it is, and it works fine: if you only want the "To" items, look at each recipient's `Type` property. – Tim Williams Jun 11 '19 at 15:00
  • 2
    Why is this question tagged vba or outlook-vba? – BrakNicku Jun 13 '19 at 09:14
  • Good call @BrakNicku. The code provided is C#. I changed the tags. – HackSlash Jun 17 '19 at 15:39

1 Answers1

1

Change:

string recipients = item.To 

To this:

string recipients = string.Join(";", item.Recipients);

The result will be an identical semi-colon delimited string but the second one will always work.

The official documentation doesn't talk about a limit on the .To property but it does tell you to use Recipients: https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.outlook._mailitem.to

HackSlash
  • 4,944
  • 2
  • 18
  • 44