user3859666
user3859666

Reputation: 279

Access the mail in Remote server

Can anyone tell me how to read the inbox of another user with his profile name and password.

I used the below code to read the my inbox. it is working fine.

Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.PostItem item = null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;

try 
   {
   app = new Microsoft.Office.Interop.Outlook.Application();
   ns = app.GetNamespace("MAPI");
   ns.Logon(null,null,false, false);

   inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
   subFolder = inboxFolder.Folders["MySubFolderName"]; //folder.Folders[1]; also works

   for(int i=1;i<=subFolder.Items.Count;i++)
   {
      item = (Microsoft.Office.Interop.Outlook.MailItem)subFolder.Items[i];
      Console.WriteLine("Body: {0}", item.Body);
   }
}

Now i need to read the inbox of another user. i used below code. But still it is accessing my inbox only. Anyone please suggest.

ns.Logon("[email protected]", "password", false, true); 

Upvotes: 0

Views: 1448

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66245

Namespace.Logon takes the name of an existing Outlook profile, not an email address. The Password parameter does nothing.

To open another user's folder, use Namespace.GetSharedDefaultFolder. Note that the current user must have an explicit right to access that folder.

Upvotes: 1

Related Questions