Winmail API
Project description
Winmail
介绍
Winmail Server 工具类
接口版本: 1.1、1.2
【建议使用】Winmail OpenAPI接口。 【不建议使用】获取Winmail信息和COM接口,Python需运行在Winmail所在机器。
安装
pip install winmail
更新历史
2023.11.20
- 删除包里多余文件
2023.11.17
- 版本号使用日期,更改到2023.11.17。
- 增加OpenApi1.2接口。
使用说明
服务启停
from winmail import start_winmail_service, stop_winmail_service
start_winmail_service()
stop_winmail_service()
OpenApi12说明
接口按官方OpenApi1.2版本完成,提供基础的参数提示,方便使用。方法名使用Winmail接口中的方法名命名,有点分隔符的替换为下划线。比如方法domain.added -> domain_added。
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官方文档。
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
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"))
属性包含:
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
方法包含:
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数据库,请在实例化时初始化数据库密码。如:
from winmail import Winmail
wm = Winmail('mysql-password')
wm.connect_db()
如果Winmail中使用了Sqlite数据库,实例化时不需要密码。但在使用connect_db时,必须指定Sqlite操作的数据库文件路径,如:
from winmail import Winmail
wm = Winmail()
wm.connect_db(wm.winmail_mailuser_conf_path)
Com接口说明
:warning:Python必须运行在Winmail服务器上。只支持Windows平台,暂未全部完成Com接口,不建议使用。
请参考Winmail的Com接口文档。
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file winmail-2023.11.21.tar.gz.
File metadata
- Download URL: winmail-2023.11.21.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8417671c2edef19c44d8296cc06a06ae1338df112d8cd32d226b3ab637c8efc5
|
|
| MD5 |
fd90d5d0fab14651f8a0865f865489c7
|
|
| BLAKE2b-256 |
2f3a0e273f726ba3f32ab7f50b193f1376f41e533f6befa9a8ed5f78a58e45b6
|
File details
Details for the file winmail-2023.11.21-py3-none-any.whl.
File metadata
- Download URL: winmail-2023.11.21-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eeeb9b6203d586f8eb36a6914672f705a7dbb10981a1486fc22f2ea9461ec7f
|
|
| MD5 |
12c8184f54b62c0a6363e2fdce3f0f3b
|
|
| BLAKE2b-256 |
38a229ed97d9637c2ff93b1570d22f2aa51e6622bd69ebbfada5ed3c4d60958b
|