Results 1 to 5 of 5

Thread: Reading Outlook 2007 .msg file with VB.Net 2010

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    38

    Reading Outlook 2007 .msg file with VB.Net 2010

    I am using the following code to get information from Outlook .msg files (created by Save As from
    Outlook), such as .SenderName, etc., as shown in the code. This works on all but two of many
    .msg files.

    The problem is that it does not work on .msg files that are actually saved meeting notices.
    I get the following error:
    Unable to cast COM object of type 'System.__ComObject' to interface type
    'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface
    call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed
    due to the following error: No such interface supported (Exception from HRESULT: 0x80004002
    (E_NOINTERFACE))

    Then I have to exit Outlook to clear the error.

    I have searched with Google and found another person who had this problem, but no solution was given.

    Any ideas of how to process the meeting notices?

    Thanks.

    Code:
      Dim oOutL As New Outlook.Application
      Dim oMail As Outlook.MailItem
      Dim email As Outlook.MailItem
    
          oMail = CType(oOutL.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
    
          Dim MsgFileName As String
          MsgFileName = ChangeToSharedPath(gsDatabaseNames(iThisDatabase))
    
          email = oMail.Application.Session.OpenSharedItem(MsgFileName)
    
          With email
            AllOfMSGPreserveCase = .SenderName & .SentOn & .To & .CC & .BCC & .Subject & .Body
            AllOfMSGPreserveCase &= AttachmentsList
          End With
    Last edited by MLarsB; Aug 3rd, 2012 at 03:05 PM. Reason: Added Dim oOutL As New Outlook.Application

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Reading Outlook 2007 .msg file with VB.Net 2010

    Take a look at MSDN etc. for Outlook.MeetingItem

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    38

    Re: Reading Outlook 2007 .msg file with VB.Net 2010

    Thanks.

    From what I have looked at of that, it is not dealing with Outlook Save As files as .msg files. This is where I am having a problem. I get an error when trying to access a .msg file which is a meeting notice rather than a message.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Reading Outlook 2007 .msg file with VB.Net 2010

    I won't pretend that I'm an expert (my Outlook days are long behind me) but I think that the .msg file retains the structure of the MeetingItem which is why it freaks out when you try to to treat it as a Mail.Item. It's gotta be worth a try (literally .... you could throw it in as an exception handler just to see if it gets you anywhere). If nothing else you can eliminate it from your enquiries!

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    38

    Re: Reading Outlook 2007 .msg file with VB.Net 2010

    I capture it with an exception, but then I have to close Outlook to clear the error.

    What I have done for now is eliminate the two meeting notices from the 1200 some .msg files I have. However, the meeting notices do have notes in them that the users would like to be able to search in addition to the other files. I have a program which lets the user entere a string to search for and then the program accesses the .msg files and searches them.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width