我正在尝试在python中实现简单的EAS客户端功能并使用此库:https://code.google.com/p/py-eas-client/
我可以成功配置,FolderSync,同步和提取以阅读邮件和下载附件。该库具有用于这些命令的内置函数,但不适用于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。谢谢你的帮助。
答案 0 :(得分:1)
想出来,这是wbxml的一个问题。使用库libwbxml工作正常。但不幸的是,python中没有包装器