none
How to create a mail enabled contact with Exchange 2010 in c# RRS feed

  • Question

  • Hi

    Could someone help me with c# code to create mail enabled contact with Exchange 2010? I am completely new in this area. We had a application which created mail enabled contact with Exchange 2003, however we will move this application to a new server which has Exchange 2010 installed. The application was built using Window Service, with exchange 2003, cdoexm.dll was used. Is there a different reference that I need in Exchange 2010 to replace cdoexm.dll?

    Many thanks for your help

    Sophie

    • Moved by Alan.GimModerator Tuesday, July 12, 2011 1:15 AM C#-related (From:Exchange Server 2010)
    Monday, July 11, 2011 10:51 PM

All replies

  • In 2010 what you shoud use is the Exchange Managemnet Shell cmdlets which you can automate from your Managed code eg see http://msdn.microsoft.com/en-us/library/ff326159(v=exchg.140).aspx . Any example of mail enabling a contact would look like

          ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
          System.Security.SecureString secureString = new System.Security.SecureString();
          string myPassword = "password";
          foreach (char c in myPassword)
            secureString.AppendChar(c);
          PSCredential credential = new PSCredential("administrator@domain.com", secureString);
          WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://servername.com.au/powershell"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
          connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
          connectionInfo.SkipCACheck = true;
          connectionInfo.SkipCNCheck = true;
    
          connectionInfo.MaximumConnectionRedirectionCount = 4;
          Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
          try
          {
            runspace.Open();
            NewMailContact(runspace);
          }
          catch (Exception exception)
          {
            if (exception is System.Management.Automation.Remoting.PSRemotingTransportException)
            {
              switch (((System.Management.Automation.Remoting.PSRemotingTransportException)exception).ErrorCode)
              {
                case 5:  //process password issue
                  break;
                case -2144108526: //Process URL issue
                  break;
                default:// process other errors
                  break;
              }
            }
          }
        }
        public static void NewMailContact(Runspace runspace) {
    
          Command ncNewMailboxContact = new Command("New-MailContact");
          ncNewMailboxContact.Parameters.Add("Name", "Fred FlintStone");
          ncNewMailboxContact.Parameters.Add("ExternalEmailAddress", "Fred@bedrock.com");
          Pipeline plPileLine = runspace.CreatePipeline();
          plPileLine.Commands.Add(ncNewMailboxContact);
          Collection<PSObject> RsResultsresults = plPileLine.Invoke();
          foreach (PSObject obj in RsResultsresults)
          {
            foreach (PSProperty Property in obj.Properties) {
              Console.WriteLine(Property.Value);
            }
          }
          plPileLine.Stop();
        }
    
    Cheers
    Glen

    Tuesday, July 12, 2011 5:04 AM
  • Hi Glen

    Many thanks for your kind help. I will give a go with your code.

    Sophie

    Tuesday, July 12, 2011 11:10 AM