Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I want to access the unread email count from Inbox for another user (I have the username and password) using C#.
I executed the code as follows:

What I have tried:

private void btnCheck_Click(object sender, EventArgs e)
       {
           try
           {
               Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.Application();
               Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");

               mapiNameSpace.Logon("user2", "pass2", false, false);

               Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
               int a = myInbox.UnReadItemCount;
               txtInbox.Text = Convert.ToString(a);

           }
           catch (Exception err)
           {
               MessageBox.Show(err.ToString());
               throw;
           }


       }


In this code, I am getting the count of my inbox. But I need the count for the user2's inbox.
Posted
Updated 13-May-19 9:29am
Comments
[no name] 13-May-19 13:17pm    
So what happened? Maybe it's to stop brute force attacks by a bot. Who are you trying to hack?
webmail123 13-May-19 14:24pm    
Hello Gerry.
I am not trying to hack any account. I have multiple inbox setup in my outlook account. (e.g. Inbox 1-> user:me, Inbox 2->user:u1, Inbox 3->user:u3). I am able to get the count of inbox 1 (Obviously) but I need to include the count of unread email from inbox 2 in a report.
[no name] 13-May-19 15:03pm    
Review the "Account Settings" for each account. You can have all go to one folder for example. Something else may be an option. Else, what's the "error message", if any.
webmail123 13-May-19 15:14pm    
Thanks for the reply. I checked in account settings and it seems those are different 'Mailboxes'.
There are no errors at all.

1 solution

The better the question, the better the answer.

C# Winforms: Accessing Outlook with Multiple Mailboxes - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900