locked
Login and Send issues with MAPI RRS feed

  • Question

  • I am completing an application that uses Extended MAPI to send and receive mail. I am mostly done with it, but I have two issues that I am stuck on.

    The code uses a profile other than the default profile. If it is installed on 10 computers, they will all use the same profile for sending and receiving messages, so this will need to be set up manually on each system.

    Unfortunately, although I am able to log on to my test account, I cannot check or receive mail. I did most of my testing using my own profile.

    I partially solved this issue by closing Outlook, changing the default profile to my test profile, reopening Outlook, and saving the password. I was then able to access the test account through my code. I then changed the default profile back to my own, and was asked to log in to the test account, but my mail opened. I changed the profile in that logon to my own, and logged in, and Outlook seems to be working okay now. I can still check the mail in the test account, but when I try to use my own profile to check my mail, I cannot access the mail. It would be nice to know what I did that allows me to check my test account now, and why I can no longer access my own through my code. This will allow us to set the system up on our customer's computers.

    The code I use to log in is below:

    	DWORD dwFlags=0;
    	if(bMultiThreadedNotifications) dwFlags|=MAPI_MULTITHREAD_NOTIFICATIONS;
    	if(bInitAsService) dwFlags|=MAPI_NT_SERVICE;
    
    	if(dwFlags) 
    	{
    		MAPIINIT_0 MAPIInit={ MAPI_INIT_VERSION, dwFlags };
    		if(MAPIInitialize(&MAPIInit)!=S_OK) return FALSE;
    	} 
    	else 
    	{
    		if(MAPIInitialize(NULL)!=S_OK) return FALSE;
    	}
    
    ...
    
    DWORD dwFlags=MAPI_EXTENDED | MAPI_EXPLICIT_PROFILE  | MAPI_NEW_SESSION;
    	if(bInitAsService) 
    		dwFlags|= MAPI_NT_SERVICE;
    	return (MAPILogonEx(NULL, (LPTSTR)szProfileName, (LPTSTR)szProfilePassword, dwFlags, &m_pSession)==S_OK);

    The other issue I have is with sending. If I am using a working account, which means I can retrieve and delete messages, I get an E_ACCESSDENIED error when I try to send mail. My send code, after creating the message, is as follows:

    HRESULT result = Message()->SubmitMessage(0);
    If anyone has insight as to what I may be doing wrong, I would greatly appreciate it. If you need additional information, please feel free to ask.

    Wednesday, December 19, 2012 9:06 PM

Answers

  • 1. What services (Exchange, POP3, etc.) did you use in the profile? What exactly do you mean by " I cannot access the mail"?

    2. Thsi is really a separate question, might be better to start a new thread. How exactly is the message created? How do you populate its properties? You really need to be more specific.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    • Marked as answer by Quist Zhang Monday, December 31, 2012 7:11 AM
    Wednesday, December 19, 2012 9:10 PM
  • As a rule of thumb, you always need to make sure that the calling process is running as the same domain user who owns the primary mailbox store in the profile.

    If you need to open other mailboxes, do that using IExchangeManageStore  after logging to the primary mailbox.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    • Marked as answer by Quist Zhang Monday, December 31, 2012 7:11 AM
    Wednesday, December 19, 2012 11:13 PM

All replies

  • 1. What services (Exchange, POP3, etc.) did you use in the profile? What exactly do you mean by " I cannot access the mail"?

    2. Thsi is really a separate question, might be better to start a new thread. How exactly is the message created? How do you populate its properties? You really need to be more specific.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    • Marked as answer by Quist Zhang Monday, December 31, 2012 7:11 AM
    Wednesday, December 19, 2012 9:10 PM
  • @Dimitry,

    You seem to be the preeminent MAPI developer on any site. Thank you for all of your assistance.

    I set the account up as Exchange, and confirmed it under Email Accounts.  I seem to be able to access both accounts now. I tried to send an email out from my own profile, and was asked to log in. After doing so, I can now get messages whether I log in as my test account or my personal account. I'm still not quite sure what I did that caused this to start working and if I can repeat it on a client system. However, it was obviously not the code but some setting in the Windows environment.

    I did post the second question in more detail on Stack Overflow, and you responded to that one. Since then I wrote a reply. For others, that question was posted here.

    Wednesday, December 19, 2012 11:03 PM
  • As a rule of thumb, you always need to make sure that the calling process is running as the same domain user who owns the primary mailbox store in the profile.

    If you need to open other mailboxes, do that using IExchangeManageStore  after logging to the primary mailbox.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    • Marked as answer by Quist Zhang Monday, December 31, 2012 7:11 AM
    Wednesday, December 19, 2012 11:13 PM