36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import urllib.request, json
|
|
|
|
# 获取 token
|
|
req = urllib.request.Request(
|
|
'https://gw.server.zgitm.com/zgapi/v1/open/token',
|
|
data=json.dumps({"systemCode": "nginxServer"}).encode('utf-8'),
|
|
headers={'Content-Type': 'application/json; charset=UTF-8'},
|
|
method='POST'
|
|
)
|
|
resp = json.loads(urllib.request.urlopen(req, timeout=10).read())
|
|
print("Token获取:", resp['code'], resp['msg'])
|
|
|
|
token = resp['data']['token']
|
|
print(f"systemName: {resp['data']['systemName']}")
|
|
|
|
# 发送邮件
|
|
req2 = urllib.request.Request(
|
|
'https://gw.server.zgitm.com/zgapi/v1/open/email/send',
|
|
data=json.dumps({
|
|
"to": "zg@zgitm.com",
|
|
"subject": "测试",
|
|
"content": "<p>测试邮件</p>",
|
|
"contentType": "html"
|
|
}).encode('utf-8'),
|
|
headers={
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
'Authorization': f'Bearer {token}'
|
|
},
|
|
method='POST'
|
|
)
|
|
try:
|
|
resp2 = json.loads(urllib.request.urlopen(req2, timeout=10).read())
|
|
print(f"邮件发送: code={resp2['code']}, msg={resp2['msg']}")
|
|
except urllib.error.HTTPError as e:
|
|
print(f"邮件发送失败: {e.code} - {e.read().decode()}")
|