Office Outlook Interop Issue

Micah Holmes 1 Reputation point
2025-01-15T17:30:42.0633333+00:00

I recently started having an issue with our email reading utility after the December 2024 Outlook update. I can no longer read email body from a folder. VS 2022 keeps crashing giving generic access errors.

Error Section Snippet:

mi.EmailBodyText = item.Body;

Full Code Snippet:

 for (int i=1;i<=subFolder.Items.Count;i++)
 {
     item = (Microsoft.Office.Interop.Outlook.MailItem)subFolder.Items[i];
     MailItem mi = new MailItem();
     mi.DateReceived = item.SentOn;
     mi.Subject = item.Subject;
     mi.EmailBodyText = item.Body;
     mi.HTMLBody = item.HTMLBody; 
     mi.FromAddress = item.SenderEmailAddress;
     foreach (Attachment att in item.Attachments)
     {
         string attachedFile = string.Format("{0}{1:00#}_{2:0#}_{3}", processingFileDir, DateTime.Today.DayOfYear, i, att.FileName);
         if (Path.GetExtension(attachedFile).ToUpper().EndsWith("ZIP"))
         {
             // put the zip file in the processing directory, extract files from it, 
             // attach those files to the email, remove the zip file
             att.SaveAsFile(attachedFile);
             ZipFile zippedAttachment = new ZipFile(attachedFile);
             zippedAttachment.ExtractAll(processingFileDir, true);

             foreach (string extractedFile in zippedAttachment.EntryFileNames)
             {
                 unzippedFilesExist = unzippedFilesExist && File.Exists(string.Concat(processingFileDir, extractedFile));
                 mi.AttachedFiles.Add(string.Concat(processingFileDir, extractedFile));
             }

             // remove the zip file
             if (File.Exists(attachedFile) && unzippedFilesExist)
             {
                 zippedAttachment.Dispose();
                 File.Delete(attachedFile);
             }
         }
         else
         {
             att.SaveAsFile(attachedFile);
             mi.AttachedFiles.Add(attachedFile);
         }
     }
     m_RetrievedMailItems.Add(mi);
 }
 return true;


When I review the body of the item its NULL

Error in VS 2022 Non Admin

Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

Error in Vs 2022 Admin

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))

I have tried:

repairing Outlook

Hard Coding Creds

Updated VS 2022

Updated NuGet Packages

Non Microsoft Outlook NuGet Package Lib

Google Searching Endlessly with little to no info for solving the issue

Open to Ideas

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,217 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jiale Xue - MSFT 48,776 Reputation points Microsoft Vendor
    2025-01-16T05:52:41.4233333+00:00

    Hi @Micah Holmes , Welcome to Microsoft Q&A,

    Make sure you are using the latest version of the Microsoft Office Interop library. Outlook may block external applications from accessing certain fields: 1. Open Outlook. 2. Go to File > Options > Trust Center > Trust Center Settings > Programmatic Access. 3. Check if "Warn me about suspicious activity" is selected. If it is, consider changing it to "Never warn me".

    Accessing items by index (subFolder.Items[i]) may cause problems with the interop library. You can iterate using a foreach loop.

    Outlook updates may introduce security measures that prevent direct access to sensitive fields. Explicitly use property access to avoid permission issues:

    foreach (var obj in subFolder.Items)
    {
        if (obj is Microsoft.Office.Interop.Outlook.MailItem mailItem)
        {
            MailItem mi = new MailItem();
            mi.DateReceived = mailItem.SentOn;
            mi.Subject = mailItem.Subject;
            mi.EmailBodyText = mailItem.Body;
            mi.HTMLBody = mailItem.HTMLBody;
            mi.FromAddress = mailItem.SenderEmailAddress;
    
            foreach (Microsoft.Office.Interop.Outlook.Attachment att in mailItem.Attachments)
            {
                string attachedFile = string.Format("{0}{1:00#}_{2:0#}_{3}", processingFileDir, DateTime.Today.DayOfYear, subFolder.Items.IndexOf(obj), att.FileName);
    
                if (Path.GetExtension(attachedFile).ToUpper().EndsWith("ZIP"))
                {
                    att.SaveAsFile(attachedFile);
                    ZipFile zippedAttachment = new ZipFile(attachedFile);
                    zippedAttachment.ExtractAll(processingFileDir, true);
    
                    foreach (string extractedFile in zippedAttachment.EntryFileNames)
                    {
                        mi.AttachedFiles.Add(string.Concat(processingFileDir, extractedFile));
                    }
    
                    if (File.Exists(attachedFile))
                    {
                        zippedAttachment.Dispose();
                        File.Delete(attachedFile);
                    }
                }
                else
                {
                    att.SaveAsFile(attachedFile);
                    mi.AttachedFiles.Add(attachedFile);
                }
            }
    
            m_RetrievedMailItems.Add(mi);
        }
    }
    
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Micah Holmes 1 Reputation point
    2025-01-21T21:32:54.51+00:00

    The solution was adjusting Microsoft Defender settings. Microsoft rolled out some updates that adjusted Defender settings that made it more restrictive. Don't know all the details but putting my user account in a unrestricted user account setup temporarily solved the issue. Now we will find out which restriction broke Outlook. Thank you Microsoft for another headache.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.