MSDN > フォーラム ホーム > Visual Studio Tools for Office > How can I change credentials to read a particular mailbox?
質問する質問する
 

質問How can I change credentials to read a particular mailbox?

  • 2009年6月26日 16:00Lucky7777 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     

    I have a simple code to get all emails from exchange server using outlook lib.

    Doesn’t mater what parameters I set for name , pass , it reads only my email mailbox

    (where name is a Profile Name)

     

    How can I change credentials to read a particular mailbox?

     

     

    Outlook.Application outlook = new Outlook.ApplicationClass ();

    Outlook.NameSpace ns = outlook.GetNamespace("Mapi" );

     

    ns.Logon(name , pass , true , true );

    Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders .olFolderInbox);

すべての返信

  • 2009年6月29日 17:29Helmut ObertannerMVP, 回答者:ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Until now you only can have one Excahnge Inbox per Profile.
    If you you want to connect to another Mailbox you need to create a temporary profile.

    Another way is to open a shared folder if you have the access rights to the other inbox.

    Something like this:
    CalendarFolder =
    ns.GetSharedDefaultFolder(myRecipient,Outlook.OlDefaultFolders .olFolderInbox);         
      
    http://msdn.microsoft.com/en-us/library/aa220116(office.11).aspx

    Hope this helps,
    greets - Helmut


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
  • 2009年6月29日 17:42Lucky7777 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Ok, thanks.

    I have 2 Accounts (so two profiles)

    trying "ns.Logon(A_ProfileName , pass , true , true ); " but it uses only default profile. (doesn't matter what profile name I use to Logon.
  • 2009年6月29日 20:08Helmut ObertannerMVP, 回答者:ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Is Outlook already running in the background when you are running this code?

    Greets - Helmut 
    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
  • 2009年6月29日 21:23Lucky7777 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    I tried both cases (on/off outlook)
  • 2009年6月30日 6:37Helmut ObertannerMVP, 回答者:ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Have you checked if there is an Outlook process running in the background using Task-Manager?
    Sometimes other programms starting Outlook without a GUI.
    e.g. Sidebar Widgets or Active Sync / Mobile Device Center.

    Also make sure that you are using the correct Profilename.
    Try to log it.

    Must be working with two profiles.

    Greets - Helmut
    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
  • 2009年6月30日 18:00Lucky7777 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    I have no outlook scheduled tasks.
    Checked "Windows Task Manager" - no outlook running.
    Double checked Profile names.

    ns.Logon() picks only default profile.
  • 2009年6月30日 19:47Helmut ObertannerMVP, 回答者:ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hello Lucky,

    I can remember -  I programmed something using two different Outlook Profiles.
    And that worked.
    It was this article here:


    http://www.codeproject.com/KB/office/BridgingTheGap.aspx

    So - can you create a simple WinForms application with a combobox that has your 2 profile-names.
    Your code should look like this.


    // Create an Outlook session
    object missing = System.Reflection.Missing.Value;

    // get the Outlook Application Object
    Outlook.Application outlookApplication = new Outlook.Application();

    // get the namespace object
    Outlook.NameSpace olNamespace = outlookApplication.GetNamespace("MAPI");

    // Logon to Session, here we use the name from
    // the comboBox to logon to a specific session.
    // If there is already an Outlook instance with
    // a Session - then this profile is used.
    olNamespace.Logon(comboBox1.Text ,  missing, true, true);
    try
    {

       // Only in Ol2007
       MessageBox.Show(olNameSpace.CurrentProfileName);

    }
    catch (System.Exception ex)
    {
       
        MessageBox.Show(this,ex.Message);
    }
    finally
    {
        fabric = null;
        olNamespace.Logoff();
        olNamespace = null;
        outlookApplication = null;

        GC.Collect();
        GC.WaitForPendingFinalizers();
    }

    Greets - Helmut
    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
  • 2009年7月3日 16:51Lucky7777 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hello Lucky,

    I can remember -  I programmed something using two different Outlook Profiles.
    And that worked.
    It was this article here:


    // Logon to Session, here we use the name from
    // the comboBox to logon to a specific session.
    // If there is already an Outlook instance with
    // a Session - then this profile is used.
    olNamespace.Logon(comboBox1.Text ,  missing, true , true );
    Greets - Helmut
    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    Right, but outlook doesn't pick another profile. All the time it runs only default one.