-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
64 lines (48 loc) · 4.24 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import msal
import smtplib
import base64
import logging
# Get a token by msal
client_id = '5c26ecdb-07d5-419a-a073-ed041ded6144'
username = '[email protected]'
scopes=["https://partner.outlook.cn/SMTP.Send"]
redirect_uri ='http://localhost'
app = msal.PublicClientApplication(client_id,authority='https://login.partner.microsoftonline.cn/d7125684-0e28-40b5-aba2-ea9580f2a204')
result = None
accounts = app.get_accounts(username=username)
if accounts:
logging.info("Account(s) exists in cache, probably with token too. Let's try.")
print("Account(s) already signed in:")
for a in accounts:
print(a["username"])
chosen = accounts[0] # Assuming the end user chose this one to proceed
print("Proceed with account: %s" % chosen["username"])
# Now let's try to find a token in cache for this account
result = app.acquire_token_silent(scopes,account=chosen)
if not result:
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
print("A local browser window will be open for you to sign in. CTRL+C to cancel.")
result = app.acquire_token_interactive(scopes)
if "access_token" in result:
print(result["access_token"])
else:
print(result.get("error"))
print(result.get("error_description"))
print(result.get("correlation_id"))
print("result: " , result)
token = result["access_token"]
user = '[email protected]'
xoauth = "user=" + user + "\x01auth=Bearer " + token + "\x01\x01"
print("之前的样子: "+xoauth)
xoauth = xoauth.encode('ascii')
xoauth = base64.b64encode(xoauth)
xoauth = xoauth.decode('ascii')
print(xoauth)
#x = 'dXNlcj1qYXNvbkBtYWp1bi5mdW4BYXV0aD1CZWFyZXIgZXlKMGVYQWlPaUpLVjFRaUxDSnViMjVqWlNJNklrbDFaRjlEV0RCbU1ubzVWeTE1VGt0VFFubEVhMEZMVDI4NWQyY3RVWEk0UldZd2RDMUZORk01WmtFaUxDSmhiR2NpT2lKU1V6STFOaUlzSW5nMWRDSTZJbDlEU2tGU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2xlcXN2a3hJV0ZYYkxrUEtXRjBLZDRQamd1NjVRTlNEN0hCcXJBMGJ0RUREMl9QZkhWcnUxU1owZFItdFhKdEZqN2syVTNBbzA5Z2VSUFRWOU95TjNNS0NQMnhjZzYzNl9Qemc3QWcBAQ=='
smtp_conn = smtplib.SMTP('smtp.partner.outlook.cn',587)
smtp_conn.set_debuglevel(True)
smtp_conn.ehlo()
smtp_conn.starttls()
smtp_conn.ehlo()
smtp_conn.docmd('AUTH', 'XOAUTH2 ' + xoauth)
smtp_conn.sendmail(user, '[email protected]', 'cool')