How can I change credentials to read a particular mailbox?<p class=MsoNormal>I have a simple code to get all emails from exchange server using outlook lib.</p> <p class=MsoNormal>Doesn’t mater what parameters I set for<span style="font-family:'Courier New';color:#a31515"> name</span> <span style="font-family:'Courier New'">, <span style="color:#a31515">pass</span> </span> , it reads only my email mailbox</p> <p class=MsoNormal>(where<span style="font-family:'Courier New';color:#a31515"> name</span> is a Profile Name)</p> <p class=MsoNormal> </p> <p class=MsoNormal>How can I change credentials to read a particular mailbox?</p> <p class=MsoNormal> </p> <p class=MsoNormal> </p> <p class=MsoNormal><span style="font-family:'Courier New'">Outlook.<span style="color:#2b91af">Application</span> outlook = <span style="color:blue">new</span> Outlook.<span style="color:#2b91af">ApplicationClass</span> ();</span></p> <p class=MsoNormal><span style="font-family:'Courier New'">Outlook.<span style="color:#2b91af">NameSpace</span> ns = outlook.GetNamespace(<span style="color:#a31515">&quot;Mapi&quot;</span> );</span></p> <p class=MsoNormal><span style="font-family:'Courier New'"> </span></p> <p class=MsoNormal><span style="font-family:'Courier New'">ns.Logon(<span style="color:#a31515">name</span> , <span style="color:#a31515">pass</span> , <span style="color:blue">true</span> , <span style="color:blue">true</span> );</span></p> <p class=MsoNormal><span style="font-family:'Courier New'">Outlook.<span style="color:#2b91af">MAPIFolder</span> inbox = ns.GetDefaultFolder(Outlook.<span style="color:#2b91af">OlDefaultFolders</span> .olFolderInbox);</span></p>© 2009 Microsoft Corporation. All rights reserved.Fri, 03 Jul 2009 16:51:47 Z96a1f460-b9b2-4fce-b959-563ec9372e60http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#96a1f460-b9b2-4fce-b959-563ec9372e60http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#96a1f460-b9b2-4fce-b959-563ec9372e60Lucky7777http://social.msdn.microsoft.com/Profile/en-US/?user=Lucky7777How can I change credentials to read a particular mailbox?<p class=MsoNormal>I have a simple code to get all emails from exchange server using outlook lib.</p> <p class=MsoNormal>Doesn’t mater what parameters I set for<span style="font-family:'Courier New';color:#a31515"> name</span> <span style="font-family:'Courier New'">, <span style="color:#a31515">pass</span> </span> , it reads only my email mailbox</p> <p class=MsoNormal>(where<span style="font-family:'Courier New';color:#a31515"> name</span> is a Profile Name)</p> <p class=MsoNormal> </p> <p class=MsoNormal>How can I change credentials to read a particular mailbox?</p> <p class=MsoNormal> </p> <p class=MsoNormal> </p> <p class=MsoNormal><span style="font-family:'Courier New'">Outlook.<span style="color:#2b91af">Application</span> outlook = <span style="color:blue">new</span> Outlook.<span style="color:#2b91af">ApplicationClass</span> ();</span></p> <p class=MsoNormal><span style="font-family:'Courier New'">Outlook.<span style="color:#2b91af">NameSpace</span> ns = outlook.GetNamespace(<span style="color:#a31515">&quot;Mapi&quot;</span> );</span></p> <p class=MsoNormal><span style="font-family:'Courier New'"> </span></p> <p class=MsoNormal><span style="font-family:'Courier New'">ns.Logon(<span style="color:#a31515">name</span> , <span style="color:#a31515">pass</span> , <span style="color:blue">true</span> , <span style="color:blue">true</span> );</span></p> <p class=MsoNormal><span style="font-family:'Courier New'">Outlook.<span style="color:#2b91af">MAPIFolder</span> inbox = ns.GetDefaultFolder(Outlook.<span style="color:#2b91af">OlDefaultFolders</span> .olFolderInbox);</span></p>Fri, 26 Jun 2009 16:00:37 Z2009-06-26T19:54:15Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#edc1b98c-c16c-40a9-8f8d-6119cb045b3fhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#edc1b98c-c16c-40a9-8f8d-6119cb045b3fHelmut Obertannerhttp://social.msdn.microsoft.com/Profile/en-US/?user=Helmut%20ObertannerHow can I change credentials to read a particular mailbox?Until now you only can have one Excahnge Inbox per Profile.<br/>If you you want to connect to another Mailbox you need to create a temporary profile.<br/><br/>Another way is to open a shared folder if you have the access rights to the other inbox.<br/><br/>Something like this:<br/>CalendarFolder = <br/>ns.GetSharedDefaultFolder(myRecipient,<span style="font-family:Courier New">Outlook.<span style="color:#2b91af">OlDefaultFolders</span> .olFolderInbox</span>);         <br/>   <br/><a href="http://msdn.microsoft.com/en-us/library/aa220116(office.11).aspx">http://msdn.microsoft.com/en-us/library/aa220116(office.11).aspx</a><br/><br/>Hope this helps,<br/>greets - Helmut<br/><br/><hr class="sig">Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]Mon, 29 Jun 2009 17:29:41 Z2009-06-29T17:29:41Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#1579d162-2cda-45d0-a307-4c5270980903http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#1579d162-2cda-45d0-a307-4c5270980903Lucky7777http://social.msdn.microsoft.com/Profile/en-US/?user=Lucky7777How can I change credentials to read a particular mailbox?Ok, thanks.<br/> <br/> I have 2 Accounts (so two profiles)<br/> <br/> trying &quot;<span style="font-family:'Courier New'">ns.Logon(<span style="color:#a31515">A_ProfileName</span> , <span style="color:#a31515">pass</span> , <span style="color:blue">true</span> , <span style="color:blue">true</span> );</span> &quot; but it uses only default profile. (doesn't matter what profile name I use to Logon.Mon, 29 Jun 2009 17:42:01 Z2009-06-29T17:42:01Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#449d1291-0a7c-447a-9128-451e4338ca81http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#449d1291-0a7c-447a-9128-451e4338ca81Helmut Obertannerhttp://social.msdn.microsoft.com/Profile/en-US/?user=Helmut%20ObertannerHow can I change credentials to read a particular mailbox?Is Outlook already running in the background when you are running this code?<br/><br/>Greets - Helmut <hr class="sig">Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]Mon, 29 Jun 2009 20:08:51 Z2009-06-29T20:08:51Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#49111bea-9bd8-4266-be95-aa7d158b732dhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#49111bea-9bd8-4266-be95-aa7d158b732dLucky7777http://social.msdn.microsoft.com/Profile/en-US/?user=Lucky7777How can I change credentials to read a particular mailbox?I tried both cases (on/off outlook) <br/>Mon, 29 Jun 2009 21:23:03 Z2009-06-29T21:23:03Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#539d7195-bc17-4d6b-a891-8de2ce8ed160http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#539d7195-bc17-4d6b-a891-8de2ce8ed160Helmut Obertannerhttp://social.msdn.microsoft.com/Profile/en-US/?user=Helmut%20ObertannerHow can I change credentials to read a particular mailbox?Have you checked if there is an Outlook process running in the background using Task-Manager?<br/>Sometimes other programms starting Outlook without a GUI.<br/>e.g. Sidebar Widgets or Active Sync / Mobile Device Center.<br/><br/>Also make sure that you are using the correct Profilename.<br/>Try to log it.<br/><br/>Must be working with two profiles.<br/><br/>Greets - Helmut<hr class="sig">Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]Tue, 30 Jun 2009 06:37:14 Z2009-06-30T06:37:14Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#cfd7fab5-7a94-4394-814d-cebd7765e8c5http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#cfd7fab5-7a94-4394-814d-cebd7765e8c5Lucky7777http://social.msdn.microsoft.com/Profile/en-US/?user=Lucky7777How can I change credentials to read a particular mailbox?I have no outlook scheduled tasks.<br/> Checked &quot;Windows Task Manager&quot; - no outlook running.<br/> Double checked Profile names.<br/> <br/> <span style="font-family:'Courier New'">ns.Logon() picks only default profile.</span>Tue, 30 Jun 2009 18:00:57 Z2009-06-30T18:00:57Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#6c09125a-3b6e-41d1-97c8-405e163c570dhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#6c09125a-3b6e-41d1-97c8-405e163c570dHelmut Obertannerhttp://social.msdn.microsoft.com/Profile/en-US/?user=Helmut%20ObertannerHow can I change credentials to read a particular mailbox?Hello Lucky,<br/><br/>I can remember -  I programmed something using two different Outlook Profiles.<br/>And that worked.<br/>It was this article here:<br/><br/><br/><a href="http://www.codeproject.com/KB/office/BridgingTheGap.aspx">http://www.codeproject.com/KB/office/BridgingTheGap.aspx</a><br/><br/>So - can you create a simple WinForms application with a combobox that has your 2 profile-names.<br/>Your code should look like this.<br/><br/><br/><span class=code-comment>//</span><span class=code-comment> Create an Outlook session<br/></span><span class=code-keyword>object</span> missing = System.Reflection.Missing.Value;<br/><br/><span class=code-comment>//</span><span class=code-comment> get the Outlook Application Object<br/></span>Outlook.Application outlookApplication = <span class=code-keyword>new</span> Outlook.Application();<br/><br/><span class=code-comment>//</span><span class=code-comment> get the namespace object<br/></span>Outlook.NameSpace olNamespace = outlookApplication.GetNamespace(<span class=code-string>&quot;</span><span class=code-string>MAPI&quot;</span>);<br/><br/><span class=code-comment>//</span><span class=code-comment> Logon to Session, here we use the name from <br/></span><span class=code-comment>//</span><span class=code-comment> the comboBox to logon to a specific session.<br/></span><span class=code-comment>//</span><span class=code-comment> If there is already an Outlook instance with <br/></span><span class=code-comment>//</span><span class=code-comment> a Session - then this profile is used.<br/></span>olNamespace.Logon(comboBox1.Text ,  missing, <span class=code-keyword>true</span>, <span class=code-keyword>true</span>);<br/><span class=code-keyword>try</span><br/>{<br/><br/>   // Only in Ol2007<br/>   MessageBox.Show(olNameSpace.CurrentProfileName);<br/><br/>}<br/><span class=code-keyword>catch</span> (System.Exception ex)<br/>{<br/>    <br/>    MessageBox.Show(<span class=code-keyword>this</span>,ex.Message);<br/>}<br/><span class=code-keyword>finally</span><br/>{<br/>    fabric = <span class=code-keyword>null</span>;<br/>    olNamespace.Logoff();<br/>    olNamespace = <span class=code-keyword>null</span>;<br/>    outlookApplication = <span class=code-keyword>null</span>;<br/><br/>    GC.Collect();<br/>    GC.WaitForPendingFinalizers();<br/>}<br/><br/>Greets - Helmut<hr class="sig">Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]Tue, 30 Jun 2009 19:47:39 Z2009-06-30T19:47:39Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#f221033e-beec-42ee-9737-5ccffe8f8c4fhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/96a1f460-b9b2-4fce-b959-563ec9372e60#f221033e-beec-42ee-9737-5ccffe8f8c4fLucky7777http://social.msdn.microsoft.com/Profile/en-US/?user=Lucky7777How can I change credentials to read a particular mailbox?<blockquote>Hello Lucky,<br/> <br/> I can remember -  I programmed something using two different Outlook Profiles.<br/> And that worked.<br/> It was this article here:<br/> <br/> <br/> <a href="http://www.codeproject.com/KB/office/BridgingTheGap.aspx"></a> <span class=code-comment>//</span> <span class=code-comment> Logon to Session, here we use the name from <br/> </span> <span class=code-comment>//</span> <span class=code-comment> the comboBox to logon to a specific session.<br/> </span> <span class=code-comment>//</span> <span class=code-comment> If there is already an Outlook instance with <br/> </span> <span class=code-comment>//</span> <span class=code-comment> a Session - then this profile is used.<br/> </span> olNamespace.Logon(comboBox1.Text ,  missing, <span class=code-keyword>true</span> , <span class=code-keyword>true</span> );<br/> <span class=code-keyword></span> Greets - Helmut <hr class=sig> Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]</blockquote> Right, but outlook doesn't pick another profile. All the time it runs only default one.<br/> <br/>Fri, 03 Jul 2009 16:51:47 Z2009-07-03T16:51:47Z