简体   繁体   中英

C# Exchange ActiveSync Client

有谁知道将 Exchange ActiveSync 协议实现到 C# 应用程序中的任何好的库,以便我可以将电子邮件与应用程序同步到服务器(例如m.google.com )?

There's a EAS-guide on MSDN that basically implements a Client in C# .

The main body of the protocol is described in MS-ASCMD .

No. ActiveSync is licensed by Microsoft, and per terms of the license you must not release open source code. Google turned the license around on Microsoft and implemented ActiveSync themselves "to test compatibility locally."

Here is a partial answer from the Microsoft documentation showing how to implement the ActiveSync WBXML protocol and the ActiveSync HTTP protocol:

// Create credentials for the user
NetworkCredential cred = new NetworkCredential("contoso\\deviceuser", "password");

//Initialize the OPTIONS request
ASOptionsRequest optionsRequest = new ASOptionsRequest();
optionsRequest.Server = "mail.contoso.com";
optionsRequest.UseSSL = true;
optionsRequest.Credentials = cred;

// Send the request
ASOptionsResponse optionsResponse = optionsRequest.GetOptions();

Console.WriteLine("Supported Versions: {0}", optionsResponse.SupportedVersions);
Console.WriteLine("Highest Supported Version: {0}", optionsResponse.HighestSupportedVersion);
Console.WriteLine("Supported Commands: {0}", optionsResponse.SupportedCommands);

// Initialize the command request
ASCommandRequest commandRequest = new ASCommandRequest();
commandRequest.Command = "Provision";
commandRequest.Credentials = cred;
commandRequest.DeviceID = "TestDeviceID";
commandRequest.DeviceType = "TestDeviceType";
commandRequest.ProtocolVersion = "14.1";
commandRequest.Server = "mail.contoso.com";
commandRequest.UseEncodedRequestLine = true;
commandRequest.User = "deviceuser";
commandRequest.UseSSL = true;

// Create the XML payload
StringBuilder xmlBuilder = new StringBuilder();
xmlBuilder.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
xmlBuilder.Append("<Provision xmlns=\"Provision:\" xmlns:settings=\"Settings:\">");
xmlBuilder.Append("    <settings:DeviceInformation>");
xmlBuilder.Append("        <settings:Set>");
xmlBuilder.Append("            <settings:Model>Test 1.0</settings:Model>");
xmlBuilder.Append("            <settings:IMEI>012345678901234</settings:IMEI>");
xmlBuilder.Append("            <settings:FriendlyName>My Test App</settings:FriendlyName>");
xmlBuilder.Append("            <settings:OS>Test OS 1.0</settings:OS>");
xmlBuilder.Append("            <settings:OSLanguage>English</settings:OSLanguage>");
xmlBuilder.Append("            <settings:PhoneNumber>555-123-4567</settings:PhoneNumber>");
xmlBuilder.Append("            <settings:MobileOperator>My Phone Company</settings:MobileOperator>");
xmlBuilder.Append("            <settings:UserAgent>TestAgent</settings:UserAgent>");
xmlBuilder.Append("        </settings:Set>");
xmlBuilder.Append("    </settings:DeviceInformation>");
xmlBuilder.Append("     <Policies>");
xmlBuilder.Append("          <Policy>");
xmlBuilder.Append("               <PolicyType>MS-EAS-Provisioning-WBXML</PolicyType> ");
xmlBuilder.Append("          </Policy>");
xmlBuilder.Append("     </Policies>");
xmlBuilder.Append("</Provision>");
commandRequest.XmlString = xmlBuilder.ToString();

// Send the request
ASCommandResponse commandResponse = commandRequest.GetResponse();

Console.WriteLine("XML Response: {0}", commandResponse.XmlString);

If you visit the link to the documentation above be sure to check the left side navigation for additional articles on the topic. All that being said, it is recommended that you use EWS instead of ActiveSync, it should be much easier to work with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM