none
Outlook Redemption C# RRS feed

  • Question

  • How to create exchange mail profile using Outlook Redemption via C#(Profman lib) ? I dont know VB and Redemption VB docs hardly for me. 
    Wednesday, August 22, 2012 12:47 PM

Answers

  • The example is at http://www.dimastr.com/redemption/profman_examples.htm#example5

    In C#, off the top of my head:

    //Create new profile, add an Exchange server to it, configure
    //and make it default
    string ProfileName = "Exchange Server Profile";
    int PR_PROFILE_UNRESOLVED_NAME = 0x6607001E;
    int PR_PROFILE_UNRESOLVED_SERVER = 0xH6608001E;
    
    ProfMan.Profiles Profiles = new ProfMan.Profiles();
    //does that profile already exist?
    try
    {
        ProfMan.Profile NewProfile = Profiles.Item(ProfileName);
    }
    catch
    {
      //No, we must create the profile. Do so without adding the default
      NewProfile = Profiles.Add(ProfileName, false, false);
    }
    
    //make the profile default
    NewProfile.Default = true;
    
    //Add Exchange service
    ProfgMan.Service ExchService = NewProfile.Services.Add("MSEMS", "Microsoft Exchange", false);
    
    //create "ProfMan.PropertyBag" object to be used later
    //in a call to ExchService.Configure
    ProfMan.PropertyBag Properties = new ProfMan.PropertyBag();
    //add the properties required to silently
    //configure the Exchange provider
    Properties.Add(PR_PROFILE_UNRESOLVED_NAME, "username") //real value must used, e.g. "dmitry"
    Properties.Add(PR_PROFILE_UNRESOLVED_SERVER, "AddressOfTheServer") //real value must used, e.g. "MyMailServer"
    
    //Silently configure the Exchange provider
    //ShowUI: 0 - never, 1 - if necessary, 2 - always
    //Note: domain logon dialog will always be shown
    //if you are not currently logged in to the same domain
    ExchService.Configure(0, , Properties)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!


    Wednesday, August 22, 2012 5:27 PM
  • These are property tags (idetified by their integer values, see the top of the code snippet) that will contain just what their names suggest.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Thursday, August 23, 2012 1:39 PM
  • You need to run your code as the domain user who is the mailbox owner, otherwise you will see the login prompt.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Monday, August 27, 2012 4:18 PM

All replies

  • The example is at http://www.dimastr.com/redemption/profman_examples.htm#example5

    In C#, off the top of my head:

    //Create new profile, add an Exchange server to it, configure
    //and make it default
    string ProfileName = "Exchange Server Profile";
    int PR_PROFILE_UNRESOLVED_NAME = 0x6607001E;
    int PR_PROFILE_UNRESOLVED_SERVER = 0xH6608001E;
    
    ProfMan.Profiles Profiles = new ProfMan.Profiles();
    //does that profile already exist?
    try
    {
        ProfMan.Profile NewProfile = Profiles.Item(ProfileName);
    }
    catch
    {
      //No, we must create the profile. Do so without adding the default
      NewProfile = Profiles.Add(ProfileName, false, false);
    }
    
    //make the profile default
    NewProfile.Default = true;
    
    //Add Exchange service
    ProfgMan.Service ExchService = NewProfile.Services.Add("MSEMS", "Microsoft Exchange", false);
    
    //create "ProfMan.PropertyBag" object to be used later
    //in a call to ExchService.Configure
    ProfMan.PropertyBag Properties = new ProfMan.PropertyBag();
    //add the properties required to silently
    //configure the Exchange provider
    Properties.Add(PR_PROFILE_UNRESOLVED_NAME, "username") //real value must used, e.g. "dmitry"
    Properties.Add(PR_PROFILE_UNRESOLVED_SERVER, "AddressOfTheServer") //real value must used, e.g. "MyMailServer"
    
    //Silently configure the Exchange provider
    //ShowUI: 0 - never, 1 - if necessary, 2 - always
    //Note: domain logon dialog will always be shown
    //if you are not currently logged in to the same domain
    ExchService.Configure(0, , Properties)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!


    Wednesday, August 22, 2012 5:27 PM
  • Thank you, Dmitry !
    Thursday, August 23, 2012 8:46 AM
  • And last one question. What is PR_PROFILE_UNRESOLVED_NAME and PR_PROFILE_UNRESOLVED_SERVER ? What this variables for ? 
    Thursday, August 23, 2012 9:35 AM
  • These are property tags (idetified by their integer values, see the top of the code snippet) that will contain just what their names suggest.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Thursday, August 23, 2012 1:39 PM
  • Is it possible to hardcode profile username and password for automatic log on ? 
    • Edited by sizov.ilya Friday, August 24, 2012 9:58 AM
    Friday, August 24, 2012 8:44 AM
  • No, EX provider always uses the identity of the current user to authenticate.

    Are you opening a mailbox owned by another domain user? Is your app running under a local or a doimain account?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!


    Friday, August 24, 2012 2:01 PM
  • My app and Outlook installed on local machine with local account.
    Monday, August 27, 2012 7:55 AM
  • You need to run your code as the domain user who is the mailbox owner, otherwise you will see the login prompt.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Monday, August 27, 2012 4:18 PM