Error when trying to convert Exchange address extended format to email address

Add-in Express™ Support Service
That's what is more important than anything else

Error when trying to convert Exchange address extended format to email address
Exchange and extended format 
Glenn r


Guest


Went online and collected more detail.

-Customer is running MS/Outlook 2007 and is connected to Exchange (see attached screenshot for build number) -It throws an exception on the following line (If m_objAddressBook.ResolveName(0, MAPI.MAPI_DIALOG, Nothing, adrListPtr) = MAPI.S_OK Then). The call to ResolveName throws an exception and displays a dialog box (visually) with an error that it cannot recognize the extended format of the address. See attached screenshots.

Any ideas?
Posted 22 Nov, 2011 12:38:37 Top
Glenn r


Guest


I'm using the following function I got off your site to format my exchange email addresses. This has been working good until now. I get the following error. Do you have any idea why? My customer is using Outlook 2007 with Exchange 2007. I can get more details if needed.

unhandled exception:
unhandled exception has occured in you applicatio...
exception from HRESULT: 0x80040113

Private Function GetSMTPAddress(ByVal exchangeAddress As String) As String

' Purpose : Exchange email addresses are stored in an extended
format. Assemble an email address in the form user@domain.tld.
' Accepts : Nothing
' Returns : Nothing

Dim smtpAddress As String = String.Empty

If m_objAddressBook Is Nothing Then
m_objAddressBook = GetAddrBook()
End If

If m_objAddressBook IsNot Nothing Then
Try
Dim szPtr As IntPtr = IntPtr.Zero
Dim propValuePtr As IntPtr = Marshal.AllocHGlobal(16)
Dim adrListPtr As IntPtr = Marshal.AllocHGlobal(16)

Marshal.WriteInt32(propValuePtr, MAPI.PR_DISPLAY_NAME)
Marshal.WriteInt32(New IntPtr(propValuePtr.ToInt32() + 4),
0)
Posted 22 Nov, 2011 12:45:22 Top
Glenn r


Guest


0)
szPtr = Marshal.StringToHGlobalAnsi(exchangeAddress)
Marshal.WriteInt64(New IntPtr(propValuePtr.ToInt32() + 8),
szPtr.ToInt32())

Marshal.WriteInt32(adrListPtr, 1)
Marshal.WriteInt32(New IntPtr(adrListPtr.ToInt32() + 4), 0)
Marshal.WriteInt32(New IntPtr(adrListPtr.ToInt32() + 8), 1)
Marshal.WriteInt32(New IntPtr(adrListPtr.ToInt32() + 12),
propValuePtr.ToInt32())
Try
If m_objAddressBook.ResolveName(0, MAPI.MAPI_DIALOG, Nothing, adrListPtr) = MAPI.S_OK Then
Dim spValue As SPropValue = New SPropValue()
Dim pcount As Integer = Marshal.ReadInt32(New
IntPtr(adrListPtr.ToInt32() + 8))
Dim props As IntPtr = New IntPtr(Marshal.ReadInt32(New IntPtr(adrListPtr.ToInt32() + 12)))
For i As Integer = 0 To pcount - 1
spValue = Marshal.PtrToStructure(New
IntPtr(props.ToInt32() + (16 * i)), GetType(SPropValue))
If spValue.ulPropTag = MAPI.PR_ENTRYID Then
X Dim addrEntryPtr As IntPtr = IntPtr.Zero
X Dim propAddressPtr As IntPtr = IntPtr.Zero
X Dim objType As UInteger = 0
X Dim cb As UInteger = spValue.Value And &HFFFFFFFF
X Dim entryID As IntPtr = New IntPtr(spValue.Value >> 32)
X If m_objAddressBook.OpenEntry(cb, entryID, IntPtr.Zero, 0, objType, addrEntryPtr) = MAPI.S_OK Then
X Try
X If MAPI.HrGetOneProp(addrEntryPtr, MAPI.PR_EMS_AB_PROXY_ADDRESSES, propAddressPtr) = MAPI.S_OK Then
X Dim emails As IntPtr = IntPtr.Zero
X Dim addrValue As SPropValue = Marshal.PtrToStructure(propAddressPtr, GetType(SPropValue))
X Dim acount As Integer = addrValue.Value And &HFFFFFFFF
X Dim pemails As IntPtr = New IntPtr(addrValue.Value >> 32)
X For j As Integer = 0 To acount -
1
X emails = New IntPtr(Marshal.ReadInt32(New IntPtr(pemails.ToInt32() + (4 * j))))
X smtpAddress =
Marshal.PtrToStringAnsi(emails)
X If
smtpAddress.IndexOf("SMTP:") = 0 Then
X smtpAddress = smtpAddress.Sub string(5, smtpAddress.Length - 5)
X Return smtpAddress
X End If
X Next j
X End If
X Finally
X If propAddressPtr <> IntPtr.Zero Then Marshal.Release(propAddressPtr)
X If addrEntryPtr <> IntPtr.Zero Then
Marshal.Release(addrEntryPtr)
X End Try
X End If
End If
Next i
End If
Finally
Marshal.FreeHGlobal(szPtr)
Marshal.FreeHGlobal(propValuePtr)
Marshal.FreeHGlobal(adrListPtr)
End Try
Finally
End Try
End If
Return smtpAddress
End Function
Posted 22 Nov, 2011 12:45:35 Top
Eugene Astafiev


Guest


Hi Glenn,

exception from HRESULT: 0x80040113


Please take a look at the following articles in the web:

http://support.microsoft.com/kb/905813
http://blogs.msdn.com/b/dgoldman/archive/2007/04/19/you-receive-an-0x8004010f-error-message-when-you-try-to-synchronize-the-offline-address-list-on-an-exchange-server-2003-server-in-outlook-2003.aspx
http://technet.microsoft.com/en-us/library/cc411331%28EXCHG.80%29.aspx

It looks like the issue depends on the Exchange server settings and doesn't relate to Add-in Express.

Am I on the right avenue? Is this the case?
Posted 23 Nov, 2011 08:05:05 Top
Glenn r


Guest


One of your colleagues published a solution to this problem. Can you please check to see if this will handle offline addressbooks. From the responses in the thread below the article I think it has been revised to support this. Also, I clicked the link to download the source code. Its a dll. What exactly am I to download. Thanks, Glenn

http://www.add-in-express.com/creating-addins-blog/2009/05/08/outlook-exchange-email-address-smtp/
Posted 23 Nov, 2011 14:12:29 Top
Dmitry Kostochko


Add-in Express team


Posts: 2887
Joined: 2004-04-05
Hi Glenn,

I created that sample and I do remember that there were 2 ways of getting an SMTP address there:
- one uses address book and the Resolve method
- and the other uses the PR_SMTP_ADDRESS (aka PR_EMAIL) property

I have just downloaded both sources, they are zip files, not dlls. I am going to re-test both variants later today and I think the second way will work for Offline mode. In the meanwhile, please use these direct download links, and try to test approach #2 on your side:
http://www.add-in-express.com/files/howtos/blog/adx-ol-smtp-address-cs.zip
http://www.add-in-express.com/files/howtos/blog/adx-ol-smtp-address-vb.zip
Posted 24 Nov, 2011 06:51:36 Top
Dmitry Kostochko


Add-in Express team


Posts: 2887
Joined: 2004-04-05
Hi Glenn,

I have just finished testing the code against Outlook 2007 in Offline mode.

1. The Resolve method of the IAddrBook interface cannot resolve an Exchange-based address and shows the dialog box.
2. The IMailUser interface (that is retrieved from the Outlook.AddressEntry.MAPIOBJECT property) does not have the PR_SMTP_ADDRESS field. Only the following fields can be accessed offline:
PR_ADDRTYPE
PR_DISPLAY_NAME
PR_DISPLAY_TYPE
PR_EMAIL_ADDRESS (it contains an Exchange-based address)
PR_ENTRYID
PR_OBJECT_TYPE
PR_RECORD_KEY
PR_SEARCH_KEY
PR_TEMPLATEID

So, neither way works in Offline mode of Outlook 2007. I can only suggest you check if Outlook is offline or not, and if it is offline, prompt your users to switch online.
Posted 24 Nov, 2011 11:17:56 Top
Glenn r


Guest


In in a bit of a time crunch, you wouldn't happen to know how to test if an outlook address book is online or offline would you?
Posted 25 Nov, 2011 15:41:39 Top
Dmitry Kostochko


Add-in Express team


Posts: 2887
Joined: 2004-04-05
Hi Glenn,

The Object Model of Outlook 2000 has the Namespace.Offline property. You can use it to determine if Outlook online or offline.

Also, the Namespace.ExchangeConnectionMode property was introduced in the Outlook 2003 Object Model. This property returns an enumeration instead of a simple boolean, you can use it if your add-in targets Outlook 2003 and higher.
Posted 28 Nov, 2011 05:08:53 Top
Glenn r


Guest


Dmitry, I had a chance to further my investigation on my customers system. I clicked account settings from the tools menu. From the e-mail tab I clicked the change button. The 'Use cached exchange mode' was checked. I unchecked and tried the function and it still failed. Does unchecking this mean the addressbook is online? If not how can I manually set outlook so that it is online and I can test this theory?
Posted 21 Dec, 2011 15:57:22 Top