471,092 Members | 1,158 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Outlook fails to connect to Exchange Server profile

I am using the Microsoft Office 11.0 Object library to connect to outlook. My code is as follows:
Expand|Select|Wrap|Line Numbers
  1.      _ApplicationPtr application("Outlook.Application");
  2.     CComPtr<_NameSpace> ns;
  3.     CComPtr<_NameSpace> session;
  4.     hr = application->GetNamespace(CComBSTR("MAPI"),&session.p);
  5.     if(hr != S_OK) return hr;
  6.     hr = application->get_Session(&session.p);
  7.     if(hr != S_OK) return hr;
  8.     hr = session->Logon(CComVariant(profile),CComVariant(""),CComVariant(false),CComVariant(true));
  9.     if(hr != S_OK) return hr;
  10.     Outlook::OlExchangeConnectionMode connectionMode;
  11.     hr = session->get_ExchangeConnectionMode(&connectionMode);
  12.     CComPtr<Recipient> recp;
  13.     hr = session->get_CurrentUser(&recp.p);
  14.     CComBSTR name;
  15.     hr = recp->get_Name(&name.m_str);
  16.     return hr;
  17.  
The code is used to get the user-Name of the given profile. I am trying to Logon to an Exchange Server and get the userName.

When outlook is closed everything works fine. i.e given an Exchange Server profile i gets its userName.

But when outlook is open there arises two cases,
The outlook is open and an Exchange-Server connection is open. In this case also i get the proper userName.

But when outlook is open in some other session, say an POP3 for some other user, In this case, I fail to get the UserName of the ExchangeServer. Instead I get the UserName of the PoP3 account.

I have tried, using the various combinations for the Logon, but none seems to give the desired results.
Can some-one correct the code so that it returns always the correct user name.
Oct 20 '07 #1
1 3110
RedSon
5,000 Expert 4TB
You might have better luck if you try searching MSDN for your answer.
Nov 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by Joseph Kormann | last post: by
1 post views Thread by isurug | last post: by
6 posts views Thread by AMP | last post: by
2 posts views Thread by =?Utf-8?B?RU1jQ2FydGh5?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.