Name | winmail JSON |
Version |
2023.11.21
JSON |
| download |
home_page | http://winmail.cn |
Summary | Winmail API |
upload_time | 2023-11-21 02:29:48 |
maintainer | |
docs_url | None |
author | Sway |
requires_python | >=3.6.0 |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Winmail
## 介绍
[Winmail](http://winmail.cn) Server 工具类
接口版本: 1.1、1.2
【建议使用】Winmail OpenAPI接口。
【不建议使用】获取Winmail信息和COM接口,Python需运行在Winmail所在机器。
## 安装
```bash
pip install winmail
```
## 更新历史
2023.11.20
- 删除包里多余文件
2023.11.17
- 版本号使用日期,更改到2023.11.17。
- 增加OpenApi1.2接口。
## 使用说明
### 服务启停
```python
from winmail import start_winmail_service, stop_winmail_service
start_winmail_service()
stop_winmail_service()
```
### OpenApi12说明
接口按官方OpenApi1.2版本完成,提供基础的参数提示,方便使用。方法名使用Winmail接口中的方法名命名,有点分隔符的替换为下划线。比如方法domain.added -> domain_added。
```python
from winmail import OpenApi12
api = OpenApi12('localhost', 6080, 'bt6aWe18d5b', 'btt387e78f6871aea2016aR3916eb65e299b7affHb')
login_result = api.login('admin', 'adminpassword', manage_path='admin')
print(login_result)
result = api.user_edited(name='usera', password='newpassword', domain='test.com', changedpwd=1, authtype=0, status=0)
print(result)
```
1.2版本接口中未包含的可以参考以下调用OpenApi通用类。
### OpenApi说明
可以使用HTTP、HTTPS请求,不检查证书。具体OpenApi的接口完整手册请查看Winmail官方文档。
```python
from winmail import OpenApi as WinmailApi
server = '192.168.1.195'
port = 6080
apikey = 'bt6aWe18d5b'
apisecret = 'btt387e78f6871aea2016aR3916eb65e299b7affHb'
# 管理员接口示例
manage_path = 'admin'
user = 'admin'
pwd = 'adminpassword'
api = WinmailApi(server, port, apikey, apisecret, use_ssl=False)
login_result = api.login(user, pwd, manage_path)
if login_result['result'] == 'ok':
# 更新session id防止会话过期,默认为30分钟过期。
if api.update_session():
print('update ok')
else:
print('update failed')
# 取域名列表,按API接口说明的参数字典
method_params = {
"method": "domain"
}
method_result = api.get_api(**method_params)
if method_result['result'] == 'ok':
print(method_result)
else:
print(method_result)
else:
print(login_result)
# 邮箱用户接口示例
user = 'usera'
pwd = 'mypassword'
# 邮件用户的参考:sessid包含的webmail风格。如果是手机可以使用6,普通PC用0
tid = 6
api = WinmailApi(server, port, apikey, apisecret, use_ssl=False)
login_result = api.login(user, pwd, tid=tid)
if login_result['result'] == 'ok':
# print(api.url)
# print(api.sessid)
if api.update_session():
print('update ok')
else:
print('update failed')
# 写邮件操作示例
# 上传附件操作,如果有多个附件可以一次请求也可以多次请求。每次请求的附件都会保留在邮件上除非使用reset清除。建议上传前清一下附件缓存
method_params = {
"method": "newmsg.reset",
}
method_result = api.get_api(**method_params)
if method_result['result'] != 'ok':
print(method_result)
# 第一次上传多个附件
method_params = {
"method": "upload.upload",
"attachfile": ['E://logs//webmail.log',
'E://logs//system.log']
}
method_result = api.get_api(**method_params)
if method_result['result'] != 'ok':
print(method_result)
# 第二次上传单个附件
method_params = {
"method": "upload.upload",
"attachfile": 'E://logs//admin.log'
}
method_result = api.get_api(**method_params)
if method_result['result'] != 'ok':
print(method_result)
# 写邮件信体
method_params = {
"method": "newmsg.send",
"from": "AA<a@195.com>",
"to": "B用户<b@195.com>",
"subject": 'OpenApi写信测试',
"msgbody": "<font color=red>RED content</font>",
"ishtml": '1',
"savetosent": '1'
}
method_result = api.get_api(**method_params)
if method_result['result'] == 'ok':
print(method_result)
else:
print(method_result)
else:
print(login_result)
```
### Winmail模块说明
:warning:Python必须运行在Winmail服务器上。不建议使用。
Winmail模板主要提供Winmail相关的参数路径获取。比如安装目录,域的邮件、网盘存储目录,用户邮件、网盘存储目录等。
也可以获取域名,用户,组列表。因为是直接读取配置文件和数据库,Openapi有接口的,建议使用OpenAPI接口。
#### 初始化和数据库连接说明
已经支持的数据库为Sqlite、mysql、postgresql。
##### 导入Winmail
```python
from winmail import Winmail
wm = Winmail()
print(wm.get_mailarchive_path())
print(wm.get_user_alias_list())
# 按XML路径获取system.cfg中的配置项
print(wm.get_sys_config("./dboption/dbtype"))
```
属性包含:
```txt
winmail_path,
winmail_sys_conf_path,
winmail_domain_conf_path,
winmail_mailgroup_conf_path,
winmail_mailuser_stat_conf_path,
winmail_mailuser_conf_path,
db_type
```
方法包含:
```txt
connect_db,
get_sys_config,
get_db_type,
check_winmail_path,
get_user_mailstore_path,
get_user_netstore_path,
get_domain_mailstore_path,
get_domain_netstore_path,
get_mailbackup_path,
get_mailarchive_path,
get_pri_domain,
get_domain_list,
get_all_domain_list,
get_domain_tuple_list,
get_user_list,
get_user_alias_list,
get_group_list,
check_pri_domain
```
Winmail中如果使用了Mysql数据库,请在实例化时初始化数据库密码。如:
```python
from winmail import Winmail
wm = Winmail('mysql-password')
wm.connect_db()
```
如果Winmail中使用了Sqlite数据库,实例化时不需要密码。但在使用connect_db时,必须指定Sqlite操作的数据库文件路径,如:
```python
from winmail import Winmail
wm = Winmail()
wm.connect_db(wm.winmail_mailuser_conf_path)
```
### Com接口说明
:warning:Python必须运行在Winmail服务器上。只支持Windows平台,暂未全部完成Com接口,不建议使用。
请参考Winmail的Com接口文档。
```python
from winmail import ComApi as WinmailCom
wc = WinmailCom()
winmail_db_path = wc.get_db_path()
add_domain = wc.add_domain('test.com')
print(add_domain)
```
Raw data
{
"_id": null,
"home_page": "http://winmail.cn",
"name": "winmail",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6.0",
"maintainer_email": "",
"keywords": "",
"author": "Sway",
"author_email": "sway_wang@foxmail.com",
"download_url": "https://files.pythonhosted.org/packages/2f/3a/0e273f726ba3f32ab7f50b193f1376f41e533f6befa9a8ed5f78a58e45b6/winmail-2023.11.21.tar.gz",
"platform": null,
"description": "# Winmail\n\n## \u4ecb\u7ecd\n\n[Winmail](http://winmail.cn) Server \u5de5\u5177\u7c7b\n\n\u63a5\u53e3\u7248\u672c\uff1a 1.1\u30011.2\n\n\u3010\u5efa\u8bae\u4f7f\u7528\u3011Winmail OpenAPI\u63a5\u53e3\u3002\n\u3010\u4e0d\u5efa\u8bae\u4f7f\u7528\u3011\u83b7\u53d6Winmail\u4fe1\u606f\u548cCOM\u63a5\u53e3\uff0cPython\u9700\u8fd0\u884c\u5728Winmail\u6240\u5728\u673a\u5668\u3002\n\n## \u5b89\u88c5\n\n```bash\npip install winmail\n```\n\n## \u66f4\u65b0\u5386\u53f2\n\n2023.11.20\n\n- \u5220\u9664\u5305\u91cc\u591a\u4f59\u6587\u4ef6\n\n2023.11.17\n\n- \u7248\u672c\u53f7\u4f7f\u7528\u65e5\u671f\uff0c\u66f4\u6539\u52302023.11.17\u3002\n- \u589e\u52a0OpenApi1.2\u63a5\u53e3\u3002\n\n\n\n## \u4f7f\u7528\u8bf4\u660e\n\n### \u670d\u52a1\u542f\u505c\n\n```python\nfrom winmail import start_winmail_service, stop_winmail_service\n\nstart_winmail_service()\nstop_winmail_service()\n```\n\n\n\n### OpenApi12\u8bf4\u660e\n\n\u63a5\u53e3\u6309\u5b98\u65b9OpenApi1.2\u7248\u672c\u5b8c\u6210\uff0c\u63d0\u4f9b\u57fa\u7840\u7684\u53c2\u6570\u63d0\u793a\uff0c\u65b9\u4fbf\u4f7f\u7528\u3002\u65b9\u6cd5\u540d\u4f7f\u7528Winmail\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u540d\u547d\u540d\uff0c\u6709\u70b9\u5206\u9694\u7b26\u7684\u66ff\u6362\u4e3a\u4e0b\u5212\u7ebf\u3002\u6bd4\u5982\u65b9\u6cd5domain.added -> domain_added\u3002\n\n```python\nfrom winmail import OpenApi12\n\napi = OpenApi12('localhost', 6080, 'bt6aWe18d5b', 'btt387e78f6871aea2016aR3916eb65e299b7affHb')\n\nlogin_result = api.login('admin', 'adminpassword', manage_path='admin')\nprint(login_result)\nresult = api.user_edited(name='usera', password='newpassword', domain='test.com', changedpwd=1, authtype=0, status=0)\nprint(result)\n```\n\n1.2\u7248\u672c\u63a5\u53e3\u4e2d\u672a\u5305\u542b\u7684\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u8c03\u7528OpenApi\u901a\u7528\u7c7b\u3002\n\n### OpenApi\u8bf4\u660e\n\n\u53ef\u4ee5\u4f7f\u7528HTTP\u3001HTTPS\u8bf7\u6c42\uff0c\u4e0d\u68c0\u67e5\u8bc1\u4e66\u3002\u5177\u4f53OpenApi\u7684\u63a5\u53e3\u5b8c\u6574\u624b\u518c\u8bf7\u67e5\u770bWinmail\u5b98\u65b9\u6587\u6863\u3002\n\n```python\n\nfrom winmail import OpenApi as WinmailApi\n\nserver = '192.168.1.195'\nport = 6080\napikey = 'bt6aWe18d5b'\napisecret = 'btt387e78f6871aea2016aR3916eb65e299b7affHb'\n\n# \u7ba1\u7406\u5458\u63a5\u53e3\u793a\u4f8b\nmanage_path = 'admin'\nuser = 'admin'\npwd = 'adminpassword' \napi = WinmailApi(server, port, apikey, apisecret, use_ssl=False)\n\nlogin_result = api.login(user, pwd, manage_path)\n\nif login_result['result'] == 'ok':\n # \u66f4\u65b0session id\u9632\u6b62\u4f1a\u8bdd\u8fc7\u671f\uff0c\u9ed8\u8ba4\u4e3a30\u5206\u949f\u8fc7\u671f\u3002\n if api.update_session():\n print('update ok')\n else:\n print('update failed')\n\n # \u53d6\u57df\u540d\u5217\u8868\uff0c\u6309API\u63a5\u53e3\u8bf4\u660e\u7684\u53c2\u6570\u5b57\u5178\n method_params = {\n \"method\": \"domain\"\n }\n\n method_result = api.get_api(**method_params)\n \n if method_result['result'] == 'ok':\n print(method_result)\n else:\n print(method_result)\n\nelse:\n print(login_result)\n\n\n# \u90ae\u7bb1\u7528\u6237\u63a5\u53e3\u793a\u4f8b\nuser = 'usera'\npwd = 'mypassword'\n# \u90ae\u4ef6\u7528\u6237\u7684\u53c2\u8003\uff1asessid\u5305\u542b\u7684webmail\u98ce\u683c\u3002\u5982\u679c\u662f\u624b\u673a\u53ef\u4ee5\u4f7f\u75286\uff0c\u666e\u901aPC\u75280\ntid = 6\napi = WinmailApi(server, port, apikey, apisecret, use_ssl=False)\n\nlogin_result = api.login(user, pwd, tid=tid)\nif login_result['result'] == 'ok':\n # print(api.url)\n # print(api.sessid)\n\n if api.update_session():\n print('update ok')\n else:\n print('update failed')\n\n # \u5199\u90ae\u4ef6\u64cd\u4f5c\u793a\u4f8b\n # \u4e0a\u4f20\u9644\u4ef6\u64cd\u4f5c\uff0c\u5982\u679c\u6709\u591a\u4e2a\u9644\u4ef6\u53ef\u4ee5\u4e00\u6b21\u8bf7\u6c42\u4e5f\u53ef\u4ee5\u591a\u6b21\u8bf7\u6c42\u3002\u6bcf\u6b21\u8bf7\u6c42\u7684\u9644\u4ef6\u90fd\u4f1a\u4fdd\u7559\u5728\u90ae\u4ef6\u4e0a\u9664\u975e\u4f7f\u7528reset\u6e05\u9664\u3002\u5efa\u8bae\u4e0a\u4f20\u524d\u6e05\u4e00\u4e0b\u9644\u4ef6\u7f13\u5b58\n method_params = {\n \"method\": \"newmsg.reset\",\n }\n method_result = api.get_api(**method_params)\n if method_result['result'] != 'ok':\n print(method_result)\n\n # \u7b2c\u4e00\u6b21\u4e0a\u4f20\u591a\u4e2a\u9644\u4ef6\n method_params = {\n \"method\": \"upload.upload\",\n \"attachfile\": ['E://logs//webmail.log',\n 'E://logs//system.log']\n }\n method_result = api.get_api(**method_params)\n if method_result['result'] != 'ok':\n print(method_result)\n # \u7b2c\u4e8c\u6b21\u4e0a\u4f20\u5355\u4e2a\u9644\u4ef6\n method_params = {\n \"method\": \"upload.upload\",\n \"attachfile\": 'E://logs//admin.log'\n }\n method_result = api.get_api(**method_params)\n if method_result['result'] != 'ok':\n print(method_result)\n\n # \u5199\u90ae\u4ef6\u4fe1\u4f53\n method_params = {\n \"method\": \"newmsg.send\",\n \"from\": \"AA<a@195.com>\",\n \"to\": \"B\u7528\u6237<b@195.com>\",\n \"subject\": 'OpenApi\u5199\u4fe1\u6d4b\u8bd5',\n \"msgbody\": \"<font color=red>RED content</font>\",\n \"ishtml\": '1',\n \"savetosent\": '1'\n }\n method_result = api.get_api(**method_params)\n\n if method_result['result'] == 'ok':\n print(method_result)\n else:\n print(method_result)\n\nelse:\n print(login_result)\n```\n\n### Winmail\u6a21\u5757\u8bf4\u660e\n\n:warning:Python\u5fc5\u987b\u8fd0\u884c\u5728Winmail\u670d\u52a1\u5668\u4e0a\u3002\u4e0d\u5efa\u8bae\u4f7f\u7528\u3002\n\nWinmail\u6a21\u677f\u4e3b\u8981\u63d0\u4f9bWinmail\u76f8\u5173\u7684\u53c2\u6570\u8def\u5f84\u83b7\u53d6\u3002\u6bd4\u5982\u5b89\u88c5\u76ee\u5f55\uff0c\u57df\u7684\u90ae\u4ef6\u3001\u7f51\u76d8\u5b58\u50a8\u76ee\u5f55\uff0c\u7528\u6237\u90ae\u4ef6\u3001\u7f51\u76d8\u5b58\u50a8\u76ee\u5f55\u7b49\u3002\n\n\u4e5f\u53ef\u4ee5\u83b7\u53d6\u57df\u540d\uff0c\u7528\u6237\uff0c\u7ec4\u5217\u8868\u3002\u56e0\u4e3a\u662f\u76f4\u63a5\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u548c\u6570\u636e\u5e93\uff0cOpenapi\u6709\u63a5\u53e3\u7684\uff0c\u5efa\u8bae\u4f7f\u7528OpenAPI\u63a5\u53e3\u3002\n\n#### \u521d\u59cb\u5316\u548c\u6570\u636e\u5e93\u8fde\u63a5\u8bf4\u660e\n\n\u5df2\u7ecf\u652f\u6301\u7684\u6570\u636e\u5e93\u4e3aSqlite\u3001mysql\u3001postgresql\u3002\n\n##### \u5bfc\u5165Winmail\n```python\nfrom winmail import Winmail\nwm = Winmail()\nprint(wm.get_mailarchive_path())\nprint(wm.get_user_alias_list())\n# \u6309XML\u8def\u5f84\u83b7\u53d6system.cfg\u4e2d\u7684\u914d\u7f6e\u9879\nprint(wm.get_sys_config(\"./dboption/dbtype\"))\n```\n\u5c5e\u6027\u5305\u542b\uff1a\n```txt\nwinmail_path,\nwinmail_sys_conf_path,\nwinmail_domain_conf_path,\nwinmail_mailgroup_conf_path,\nwinmail_mailuser_stat_conf_path,\nwinmail_mailuser_conf_path,\ndb_type\n```\n\n\u65b9\u6cd5\u5305\u542b\uff1a\n\n```txt\nconnect_db,\nget_sys_config,\nget_db_type,\ncheck_winmail_path,\nget_user_mailstore_path,\nget_user_netstore_path,\nget_domain_mailstore_path,\nget_domain_netstore_path,\nget_mailbackup_path,\nget_mailarchive_path,\nget_pri_domain,\nget_domain_list,\nget_all_domain_list,\t\nget_domain_tuple_list,\nget_user_list,\nget_user_alias_list,\nget_group_list,\ncheck_pri_domain\n```\n\n\n\nWinmail\u4e2d\u5982\u679c\u4f7f\u7528\u4e86Mysql\u6570\u636e\u5e93\uff0c\u8bf7\u5728\u5b9e\u4f8b\u5316\u65f6\u521d\u59cb\u5316\u6570\u636e\u5e93\u5bc6\u7801\u3002\u5982\uff1a\n```python\nfrom winmail import Winmail\nwm = Winmail('mysql-password')\nwm.connect_db()\n```\n\u5982\u679cWinmail\u4e2d\u4f7f\u7528\u4e86Sqlite\u6570\u636e\u5e93\uff0c\u5b9e\u4f8b\u5316\u65f6\u4e0d\u9700\u8981\u5bc6\u7801\u3002\u4f46\u5728\u4f7f\u7528connect_db\u65f6\uff0c\u5fc5\u987b\u6307\u5b9aSqlite\u64cd\u4f5c\u7684\u6570\u636e\u5e93\u6587\u4ef6\u8def\u5f84\uff0c\u5982\uff1a\n```python\nfrom winmail import Winmail\nwm = Winmail()\nwm.connect_db(wm.winmail_mailuser_conf_path)\n```\n\n### Com\u63a5\u53e3\u8bf4\u660e\n\n:warning:Python\u5fc5\u987b\u8fd0\u884c\u5728Winmail\u670d\u52a1\u5668\u4e0a\u3002\u53ea\u652f\u6301Windows\u5e73\u53f0\uff0c\u6682\u672a\u5168\u90e8\u5b8c\u6210Com\u63a5\u53e3\uff0c\u4e0d\u5efa\u8bae\u4f7f\u7528\u3002\n\n\u8bf7\u53c2\u8003Winmail\u7684Com\u63a5\u53e3\u6587\u6863\u3002\n\n```python\nfrom winmail import ComApi as WinmailCom\n\nwc = WinmailCom()\nwinmail_db_path = wc.get_db_path()\nadd_domain = wc.add_domain('test.com')\nprint(add_domain)\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Winmail API",
"version": "2023.11.21",
"project_urls": {
"Homepage": "http://winmail.cn"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "38a229ed97d9637c2ff93b1570d22f2aa51e6622bd69ebbfada5ed3c4d60958b",
"md5": "12c8184f54b62c0a6363e2fdce3f0f3b",
"sha256": "2eeeb9b6203d586f8eb36a6914672f705a7dbb10981a1486fc22f2ea9461ec7f"
},
"downloads": -1,
"filename": "winmail-2023.11.21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "12c8184f54b62c0a6363e2fdce3f0f3b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.0",
"size": 24293,
"upload_time": "2023-11-21T02:29:46",
"upload_time_iso_8601": "2023-11-21T02:29:46.421963Z",
"url": "https://files.pythonhosted.org/packages/38/a2/29ed97d9637c2ff93b1570d22f2aa51e6622bd69ebbfada5ed3c4d60958b/winmail-2023.11.21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2f3a0e273f726ba3f32ab7f50b193f1376f41e533f6befa9a8ed5f78a58e45b6",
"md5": "fd90d5d0fab14651f8a0865f865489c7",
"sha256": "8417671c2edef19c44d8296cc06a06ae1338df112d8cd32d226b3ab637c8efc5"
},
"downloads": -1,
"filename": "winmail-2023.11.21.tar.gz",
"has_sig": false,
"md5_digest": "fd90d5d0fab14651f8a0865f865489c7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6.0",
"size": 22817,
"upload_time": "2023-11-21T02:29:48",
"upload_time_iso_8601": "2023-11-21T02:29:48.333210Z",
"url": "https://files.pythonhosted.org/packages/2f/3a/0e273f726ba3f32ab7f50b193f1376f41e533f6befa9a8ed5f78a58e45b6/winmail-2023.11.21.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-21 02:29:48",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "winmail"
}