I am creating an application that will read the emails from Outlook's Inbox. I have this part working. Now I am trying to read the SMTP From address a selected email. I know this works differently with the Outlook versions before 2003. I have checked out CDOLive and am using scripts from there to get the SMTP address.

I am creating a VS2005 Windows app. I have as added references Outlook 11.0 object. The project is a test project so it just lists the emails in a grid, then I try to get the SMTP email address.

The project works fine in developement with Outlook 2003 and 2007 but when I try it on Outlook 2000 I get a "Cannot create ActiveX component" error.

I cannot debug it through Outlook 2000 so I can't see what is going on. I have one customer who is getting the "Cannot create ActiveX component" error with Outlook 2003.
The error is occurring at: objSession = CreateObject("MAPI.Session")

I have googled this to death and the main thing that comes through is that a file may need to be reregistered. I have checked on the maching that I am installing the test project on and they are in the registry. The only referenced dependicies that are included with the install project are office.dll, and the outlook interop. Does this mean I need to re-register one of these?
Any ideas would be appreciated.

On to the code:

vb Code:
  1. Function GetFromAddress(ByVal EntryID As String, ByVal ParentStoreID As String, ByRef ReturnFromAddresses As String, Optional ByVal Outlook2000 As Boolean = False) As Boolean ', ByRef ReturnFromAddresses As String) As Boolean
  2.         Dim ReturnBool As Boolean = True
  3.        
  4.  
  5.         'Get the SMTP address of the originator of a message
  6.         ' You can read the SMTP address of the originator of a message. But if you try to use objAddressEntry.Address you will receive the Exchange address (also known as 'Distinguish Name' if the originator is an Exchange mailbox) and not the SMTP address. Here is how to read the SMTP address:
  7.         ' MAPI property tag for SMTP address
  8.         Dim objSession As New Object, objFolder As New Object, objMessages As New Object, objMessage As New Object
  9.         Dim objField As New Object, objCDOMessage As New Object, objAddEntry As New Object
  10.         Const CdoPR_EMAIL As Integer = &H39FE001E
  11.         Const PR_EMS_AB_PROXY_ADDRESSES As Integer = &H800F101E
  12.         Try
  13.  
  14.             Dim strAddressEntryID As String = ""
  15.  
  16.             'set the ReturnFromAddresses to blank
  17.             ReturnFromAddresses = ""
  18.  
  19.             strErrorString = "Start MAPI Session"
  20.             objSession = CreateObject("MAPI.Session")
  21.  
  22.             strErrorString = "MAPI Session Logon"
  23.             objSession.Logon("", "", False, False, 0)
  24.  
  25.             If Outlook2000 Then
  26.                 'using outlook 2000
  27.                 ' Get first message from inbox
  28.                 strErrorString = "2000: Get Inbox"
  29.                 objFolder = objSession.Inbox
  30.  
  31.                 strErrorString = "2000: Get Folder Messages"
  32.                 objMessages = objFolder.Messages
  33.  
  34.                 strErrorString = "2000: Get Message(EntryID,StoreID)"
  35.                 objMessage = objMessages.GetMessage(EntryID, ParentStoreID)
  36.  
  37.                 ' Get address
  38.                 strErrorString = "2000: Get Address Entry"
  39.                 objAddEntry = objMessage.Sender
  40.  
  41.                 strErrorString = "2000: Get Address From AddEntry"
  42.                 ReturnFromAddresses = objAddEntry.Address
  43.  
  44.                 ' Check if it is an Exchange object
  45.                 strErrorString = "2000: Check for /O="
  46.                 If Microsoft.VisualBasic.Left(ReturnFromAddresses, 3).ToUpper = "/O=" Then
  47.  
  48.                     ' Get the SMTP address
  49.                     strErrorString = "2000: Get CdoPR_Email"
  50.                     strAddressEntryID = objAddEntry.ID
  51.                     ReturnFromAddresses = objSession.GetAddressEntry(strAddressEntryID).Fields(CdoPR_EMAIL).Value()
  52.  
  53.                 End If
  54.  
  55.  
  56.             Else
  57.                 'using outlook 2002 +
  58.                 strErrorString = "2002+: Get CDO Message"
  59.                 objCDOMessage = objSession.GetMessage(EntryID, ParentStoreID)
  60.  
  61.                 strErrorString = "2002+: Get CDO Sender"
  62.                 objAddEntry = objCDOMessage.Sender
  63.  
  64.                 strErrorString = "2002+: Get PR_EMS_AB_PROXY_ADDRESSES"
  65.                 objField = objAddEntry.Fields(PR_EMS_AB_PROXY_ADDRESSES)
  66.  
  67.                 strErrorString = "2002+: Loop Through Addresses"
  68.                 For Each strEMailAddress As String In objField.Value
  69.                     If Microsoft.VisualBasic.Left(strEMailAddress, 5) = "SMTP:" Then
  70.                         ReturnFromAddresses = Microsoft.VisualBasic.Mid(strEMailAddress, 6)
  71.                         Exit For
  72.                     End If
  73.                 Next
  74.  
  75.             End If
  76.  
  77.             ' Display the SMTP address of current user
  78.             MessageBox.Show("SMTP address of current user: " & ReturnFromAddresses, UtilityName, MessageBoxButtons.OK, MessageBoxIcon.Information)
  79.  
  80.             'Note that you must use exactly the way described above. Otherwise you will fail to get the SMTP address.
  81.  
  82.         Catch exp As System.UnauthorizedAccessException
  83.             MessageBox.Show("If you say NO to the security boxes then email will NOT be gathered", "Email Inbox", _
  84.                MessageBoxButtons.OK, MessageBoxIcon.Information)
  85.             ReturnBool = False
  86.             Exit Try
  87.  
  88.         Catch exp As System.Exception
  89.             MessageBox.Show("GetAddress error: " & strErrorstring & vbCrLf & exp.Message, UtilityName, MessageBoxButtons.OK)
  90.  
  91.             ReturnBool = False
  92.         End Try
  93.  
  94.         'cleanup
  95.         objSession = Nothing : objFolder = Nothing : objMessages = Nothing : objMessage = Nothing : objField = Nothing : objCDOMessage = Nothing : objAddEntry = Nothing
  96.         ReturnBool = Not IsNullOrEmpty(ReturnFromAddresses)
  97. End Function