我正在尝试在 python 中实现简单的 EAS 客户端功能并使用这个库:https ://code.google.com/p/py-eas-client/
我可以成功 Provision、FolderSync、Sync 和 Fetch 来阅读消息和下载附件。该库为这些命令内置了函数,但没有为 SendMail 内置函数。所以我正在尝试自己实现 SendMail:
def sendmail(self):
send_url = self.add_parameters(self.get_url(),
{"Cmd": "SendMail", "User": self.username, "DeviceId": self.device_id,
"DeviceType": self.device_type})
d = self.agent.request(
'POST',
send_url,
Headers({'User-Agent': ['python-EAS-Client 1.0'],
'Host': [self.server],
'MS-ASProtocolVersion': [self.server_version],
'X-MS-PolicyKey': [str(self.policy_key)],
'Content-Type': ["application/vnd.ms-sync.wbxml"],
'Authorization': [self.authorization_header()]}),
SendMailProducer())
d.addCallback(self.wbxml_response)
return d
然后这里是 SendMail wbxml 生产者:
class SendMailProducer(WBXMLProducer):
def __init__(self):
msg = """From: xyz@xyz.org
To: xyz@xyz.org
Subject: From NSync
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
This is the body text."""
wbdict = {
"SendMail": [
("ClientId", "12312312312352173263123"),
("Mime", msg)
]
}
wb = convert_dict_to_wbxml(wbdict, default_page_num=3)
print wb
return WBXMLProducer.__init__(self, wb, verbose=True)
在 dewbxml.py 中,我必须添加对 ComposeMail 命名空间的支持:
{ # Page 3 - ComposeMail
"name":"ComposeMail",
0x05: ('SendMail', None),
0x10: ('Mime', None),
0x11: ('ClientId', None)
}
使用这个我得到一个 503 错误响应。我几乎可以肯定我没有正确准备 wbxml。假设我可以成功获取策略密钥,有没有更简单的方法可以在 python 中执行 activesync SendMail?我还没有找到任何其他方式来编码 wbxml。谢谢你的帮助。