6

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

4

3 回答 3

2

MSDN 上有一个 EAS 指南,它基本上在 C# 中实现了一个客户端

该协议的主体在MS-ASCMD中进行了描述。

于 2012-09-17T09:46:45.073 回答
1

不可以。ActiveSync 由 Microsoft 许可,根据许可条款,您不得发布开源代码。谷歌在微软身上扭转了许可证,并自己实施了 ActiveSync,“以在本地测试兼容性”。

于 2012-03-06T19:04:15.027 回答
0

以下是Microsoft 文档的部分答案,展示了如何实现 ActiveSync WBXML 协议和 ActiveSync HTTP 协议:

// 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);

如果您访问上述文档的链接,请务必查看左侧导航以获取有关该主题的其他文章。话虽如此,建议您使用EWS而不是 ActiveSync,它应该更容易使用。

于 2022-01-13T19:10:18.560 回答