none
How to find out if an Outlook IMAP account has valid credentials? RRS feed

  • Question

  • Hi, 
    I'd like my Outlook add-in to know if an Outlook IMAP account has (in)valid credentials. 
    Or at least if it had been valid within the last 24 hours.Or if the connection has successfully been established within the last X hours. 

    I simply tried to access some messages or the count of the messages in any folder, but I get the values cached by Outlook, it does not force a sync/imap connection or throw any error that the connection can't be established. 
    Any Exception firing when accessing any property when the imap account has invalid credentials would also help. 

    Does anyone know if this is possible? 

    Best regards, 

    Harald Binkle




    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com


    Wednesday, January 6, 2016 2:09 PM

Answers

All replies

  • Hello Harald,

    The OOM doesn't provide anything special for that.

    You may try to synchronization process by using the Start method of the SyncObject class.  The OnError event of the SyncObject class is fired when Microsoft Outlook encounters an error while synchronizing a user’s folders using the specified Send\Receive group.

    Another way is to try to log in to the mailbox programmatically without using Outlook objects.

    Wednesday, January 6, 2016 2:59 PM
  • Hello Eugene,

    Thank you for your reply. The SyncObjects OnError event seems to work fine. Thank you for the hint. (a manual login would force the user to re-enter the password saved in Outlook, which may not be known be the user in our case)
    The only thing I may improve is a more specific failure detection.
    Although I have 12 accounts in my Outlook there is only one SyncObject. (named: "All accounts")
    This object seems to fail always with the same error code: -2146644978. (the description is on most cases not set)
    I get that error code when I set a wrong password to an IMAP account and cancel the dialog Outlook brings up.
    But I also get the same error code when disabling my entire network connection and none of my accounts is able to connect (including my primary Exchange Server account).
    Do you know if I can create a custom SyncObject syncing only one account or folder?
    Also I wasn't able to find any documentation about the error codes.

    Greetings,
    Harald


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Friday, January 8, 2016 9:28 AM
  • Hello Harald,

    The SyncObjects object is read-only. You cannot add an item to the collection. However, note that you can add one Send/Receive group using the AppFolders property which will create a Send/Receive group called Application Folders.

    Although I have 12 accounts in my Outlook there is only one SyncObject.

    You are on the wrong avenue. Try to run the following VBA code. How many message boxes do you get? 

    Public Sub Sync() 
     
     Dim nsp As Outlook.NameSpace 
     
     Dim sycs As Outlook.SyncObjects 
     
     Dim syc As Outlook.SyncObject 
     
     Dim i As Integer 
     
     Dim strPrompt As Integer 
     
     Set nsp = Application.GetNamespace("MAPI") 
     
     Set sycs = nsp.SyncObjects 
     
     For i = 1 To sycs.Count 
     
     Set syc = sycs.Item(i) 
     
     strPrompt = MsgBox("Do you wish to synchronize " & syc.Name &"?", vbYesNo) 
     
     If strPrompt = vbYes Then 
     
     syc.Start 
     
     End If 
     
     Next 
     
    End Sub

    Friday, January 8, 2016 10:13 AM
  • Hello Eugene,

    Thanks for your reply.
    The script only shows one MessageBox, like my C# code does.
    How do I programmatically create Send/Receive groups?

    I also tried getting the SyncObjects from the session instead of the namespace object, no difference.

    Best regards,

    Harald Binkle 


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Friday, January 8, 2016 10:44 AM
  • The Outlook object model doesn't provide anything for creating a custom SyncObject which may sync only one account or folder.
    Friday, January 8, 2016 11:56 AM
  • ok,

    but what does the "InAppFolderSyncObject " do?

    After running the following script I get two SyncObjects.
    The one for all accounts and one named "applicationfolder"

        Set nsp = Application.GetNamespace("MAPI")
        Set objSycs = nsp.SyncObjects
        Set objSyc = objSycs.AppFolders
        Set mpfInbox = nsp.GetDefaultFolder(olFolderInbox)
        mpfInbox.InAppFolderSyncObject = True
        objSyc.Start

    Hoping that this will create a syncobject for the inbox I tried to do that for each IMAP inbox:

     private void CheckIMAPAccounts()
            {
                m_SyncObjectsStarted = 0;
                m_SyncObjectsFinished = 0;
    
                EnsureSyncForImap();
    
                foreach (SyncObject syncObject in OutlookNamespace.SyncObjects)
                {
                    m_SyncObjects.Add(syncObject); //keep reference for events
                    syncObject.OnError += SyncObject_OnError;
                    syncObject.SyncEnd += SyncObject_SyncEnd;
                    m_SyncObjectsStarted++;
                    syncObject.Start();
                }
                Thread.Sleep(1000);
            }
    
            private void EnsureSyncForImap()
            {
                var syncObjects = OutlookNamespace.SyncObjects.AppFolders;
                foreach (RDOStore rdoStore in this.m_RdoSession.Stores)
                {
                    if(rdoStore.StoreKind == TxStoreKind.skIMAP4)
                    {
                        var inbox = rdoStore.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);
                        var olFolder = OutlookNamespace.GetFolderFromID(inbox.EntryID);
                        olFolder.InAppFolderSyncObject = true;                    
                    }
                }
                syncObjects.Start();
            }

    But no luck. Now there are still the two syncobjects only.


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com


    Friday, January 8, 2016 12:14 PM
  • The Outlook object model doesn't provide such properties. 
    Friday, January 8, 2016 12:50 PM
  • Hi,

    thanks. I fear you are right. There is no way to programmatically find out if an IMAP account can successfully be used by Outlook.


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    • Marked as answer by Harald Binkle Monday, January 11, 2016 8:12 AM
    • Unmarked as answer by Harald Binkle Monday, January 11, 2016 9:52 AM
    • Marked as answer by Harald Binkle Tuesday, January 12, 2016 11:07 AM
    Monday, January 11, 2016 8:12 AM
  • Harald,

    Marking your own posts as answers will not give you any benefits. 

    Monday, January 11, 2016 9:46 AM
  • The topic is shown as as answered, doesn't it?

    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Monday, January 11, 2016 9:53 AM
  • Hi Harald,

    If the reply of Engene helps you or resolves your issue, you may mark it as answer. If your reply has the solution of this issue, you may mark it as answer too.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 12, 2016 1:26 AM
    Moderator