|
4 | 4 |
|
5 | 5 | # SCOPES NEEDED: |
6 | 6 | # --------------- |
7 | | -# 'Mail.Send', |
8 | | -# 'MailboxSettings.Read', |
9 | | -# 'MailboxSettings.ReadWrite' |
| 7 | +# "Mail.Send", |
| 8 | +# "MailboxSettings.Read", |
| 9 | +# "MailboxSettings.ReadWrite" |
10 | 10 |
|
11 | 11 | # Define the Scopes needed to Login. |
12 | 12 | scopes = [ |
13 | | - 'Calendars.ReadWrite', |
14 | | - 'Files.ReadWrite.All', |
15 | | - 'User.ReadWrite.All', |
16 | | - 'Notes.ReadWrite.All', |
17 | | - 'Directory.ReadWrite.All', |
18 | | - 'User.Read.All', |
19 | | - 'Directory.Read.All', |
20 | | - 'Directory.ReadWrite.All', |
21 | | - 'Group.Read.All', |
22 | | - 'Group.ReadWrite.All', |
23 | | - 'Notes.Create', |
24 | | - 'Notes.Read', |
25 | | - 'Notes.ReadWrite', |
26 | | - 'Notes.Read.All', |
27 | | - 'Notes.ReadWrite.All', |
28 | | - 'Mail.Send', |
29 | | - 'MailboxSettings.Read', |
30 | | - 'MailboxSettings.ReadWrite' |
| 13 | + "Calendars.ReadWrite", |
| 14 | + "Files.ReadWrite.All", |
| 15 | + "User.ReadWrite.All", |
| 16 | + "Notes.ReadWrite.All", |
| 17 | + "Directory.ReadWrite.All", |
| 18 | + "User.Read.All", |
| 19 | + "Directory.Read.All", |
| 20 | + "Directory.ReadWrite.All", |
| 21 | + "Group.Read.All", |
| 22 | + "Group.ReadWrite.All", |
| 23 | + "Notes.Create", |
| 24 | + "Notes.Read", |
| 25 | + "Notes.ReadWrite", |
| 26 | + "Notes.Read.All", |
| 27 | + "Notes.ReadWrite.All", |
| 28 | + "Mail.Send", |
| 29 | + "MailboxSettings.Read", |
| 30 | + "MailboxSettings.ReadWrite", |
31 | 31 | ] |
32 | 32 |
|
33 | 33 | # Initialize the Parser. |
34 | 34 | config = ConfigParser() |
35 | 35 |
|
36 | 36 | # Read the file. |
37 | | -config.read('configs/config.ini') |
| 37 | +config.read("configs/config.ini") |
38 | 38 |
|
39 | 39 | # Get the specified credentials. |
40 | | -client_id = config.get('graph_api', 'client_id') |
41 | | -client_secret = config.get('graph_api', 'client_secret') |
42 | | -redirect_uri = config.get('graph_api', 'redirect_uri') |
| 40 | +client_id = config.get("graph_api", "client_id") |
| 41 | +client_secret = config.get("graph_api", "client_secret") |
| 42 | +redirect_uri = config.get("graph_api", "redirect_uri") |
43 | 43 |
|
44 | 44 | # Initialize the Client. |
45 | 45 | graph_client = MicrosoftGraphClient( |
46 | 46 | client_id=client_id, |
47 | 47 | client_secret=client_secret, |
48 | 48 | redirect_uri=redirect_uri, |
49 | 49 | scope=scopes, |
50 | | - credentials='configs/ms_graph_state.jsonc' |
| 50 | + credentials="configs/ms_graph_state.jsonc", |
51 | 51 | ) |
52 | 52 |
|
53 | 53 | # Login to the Client. |
54 | 54 | graph_client.login() |
55 | 55 |
|
56 | 56 | # Define a valid User ID. |
57 | | -USER_ID = '8bc640c57cda25b6' |
| 57 | +USER_ID = "8bc640c57cda25b6" |
58 | 58 |
|
59 | 59 | # Define a mail Item ID. |
60 | | -MAIL_ID = 'AQMkADAwATZiZmYAZC1hMDI2LTE3NTgtMDACLTAwCgBGAAADpjqwNb_dak68rN7703u' + \ |
61 | | - 'ffQcAFNKsLOjbGUuHHmYnyKdJiAAAAgEhAAAAFNKsLOjbGUuHHmYnyKdJiAAFBMTneQ' + \ |
62 | | - 'AAAA==' |
| 60 | +MAIL_ID = ( |
| 61 | + "AQMkADAwATZiZmYAZC1hMDI2LTE3NTgtMDACLTAwCgBGAAADpjqwNb_dak68rN7703u" |
| 62 | + + "ffQcAFNKsLOjbGUuHHmYnyKdJiAAAAgEhAAAAFNKsLOjbGUuHHmYnyKdJiAAFBMTneQ" |
| 63 | + + "AAAA==" |
| 64 | +) |
63 | 65 |
|
64 | 66 | # Define a mail item ID with Attachments. |
65 | | -MAIL_ID_ATTACHMENTS = 'AQMkADAwATZiZmYAZC1hMDI2LTE3NTgtMDACLTAwCgBGAAADpjqwNb+' + \ |
66 | | - 'dak68rN7703uffQcAFNKsLOjbGUuHHmYnyKdJiAAAAgEMAAAAFNKsLO' + \ |
67 | | - 'jbGUuHHmYnyKdJiAAE9ucV+AAAAA==' |
| 67 | +MAIL_ID_ATTACHMENTS = ( |
| 68 | + "AQMkADAwATZiZmYAZC1hMDI2LTE3NTgtMDACLTAwCgBGAAADpjqwNb+" |
| 69 | + + "dak68rN7703uffQcAFNKsLOjbGUuHHmYnyKdJiAAAAgEMAAAAFNKsLO" |
| 70 | + + "jbGUuHHmYnyKdJiAAE9ucV+AAAAA==" |
| 71 | +) |
68 | 72 |
|
69 | 73 | # Grab the Notes Services. |
70 | 74 | mail_services = graph_client.mail() |
71 | 75 |
|
72 | 76 | # Grab all my Messages. |
73 | | -pprint( |
74 | | - mail_services.list_my_messages() |
75 | | -) |
| 77 | +pprint(mail_services.list_my_messages()) |
76 | 78 |
|
77 | 79 | # Grab a specific message for the default user. |
78 | | -pprint( |
79 | | - mail_services.get_my_messages( |
80 | | - message_id=MAIL_ID |
81 | | - ) |
82 | | -) |
| 80 | +pprint(mail_services.get_my_messages(message_id=MAIL_ID)) |
83 | 81 |
|
84 | | -# Get a Specific User's Message. |
85 | | -pprint( |
86 | | - mail_services.get_user_messages( |
87 | | - user_id=USER_ID, |
88 | | - message_id=MAIL_ID |
89 | | - ) |
90 | | -) |
| 82 | +# Get a Specific User"s Message. |
| 83 | +pprint(mail_services.get_user_messages(user_id=USER_ID, message_id=MAIL_ID)) |
91 | 84 |
|
92 | 85 | # List the rules for a specific user.. |
93 | | -pprint( |
94 | | - mail_services.list_rules(user_id=USER_ID) |
95 | | -) |
| 86 | +pprint(mail_services.list_rules(user_id=USER_ID)) |
96 | 87 |
|
97 | 88 | # List the rules for the default user. |
98 | | -pprint( |
99 | | - mail_services.list_my_rules() |
100 | | -) |
| 89 | +pprint(mail_services.list_my_rules()) |
101 | 90 |
|
102 | 91 | # List the overrides for a specific user. |
103 | | -pprint( |
104 | | - mail_services.list_overrides(user_id=USER_ID) |
105 | | -) |
| 92 | +pprint(mail_services.list_overrides(user_id=USER_ID)) |
106 | 93 |
|
107 | 94 | # List the overrides for the default user. |
108 | | -pprint( |
109 | | - mail_services.list_my_overrides() |
110 | | -) |
| 95 | +pprint(mail_services.list_my_overrides()) |
111 | 96 |
|
112 | 97 | # List the attachments for a specific message. |
113 | | -pprint( |
114 | | - mail_services.list_my_attachements( |
115 | | - message_id=MAIL_ID_ATTACHMENTS |
116 | | - ) |
117 | | -) |
| 98 | +pprint(mail_services.list_my_attachements(message_id=MAIL_ID_ATTACHMENTS)) |
118 | 99 |
|
119 | 100 |
|
120 | 101 | # Create a new message for the default user. Keep in mind this does not send the mail. |
121 | 102 | new_message_draft = mail_services.create_my_message( |
122 | 103 | message={ |
123 | 104 | "subject": "Did you see last night's game?", |
124 | 105 | "importance": "Low", |
125 | | - "body": { |
126 | | - "contentType": "HTML", |
127 | | - "content": "They were <b>awesome</b>!" |
128 | | - }, |
129 | | - "toRecipients": [ |
130 | | - { |
131 | | - "emailAddress": { |
132 | | - "address": "alexreed1192@gmail.com" |
133 | | - } |
134 | | - } |
135 | | - ] |
| 106 | + "body": {"contentType": "HTML", "content": "They were <b>awesome</b>!"}, |
| 107 | + "toRecipients": [{"emailAddress": {"address": "alexreed1192@gmail.com"}}], |
136 | 108 | } |
137 | 109 | ) |
138 | 110 |
|
139 | 111 | # Check it out. |
140 | 112 | pprint(new_message_draft) |
141 | 113 |
|
142 | 114 | # grab the ID. |
143 | | -new_message_id = new_message_draft['id'] |
| 115 | +new_message_id = new_message_draft["id"] |
144 | 116 |
|
145 | 117 | # Send the newly created message. |
146 | 118 | mail_services.send_my_message(message_id=new_message_id) |
147 | 119 |
|
148 | | -# Let's create a new message rule, this will help with things like incoming mail. We can |
| 120 | +# Let"s create a new message rule, this will help with things like incoming mail. We can |
149 | 121 | # control what happens to mail that meets certain conditions. |
150 | 122 | my_new_message_rule = mail_services.create_my_message_rule( |
151 | 123 | rule={ |
152 | 124 | "displayName": "From partner", |
153 | 125 | "sequence": 2, |
154 | 126 | "isEnabled": True, |
155 | | - "conditions": { |
156 | | - "senderContains": [ |
157 | | - "youtube" |
158 | | - ] |
159 | | - }, |
| 127 | + "conditions": {"senderContains": ["youtube"]}, |
160 | 128 | "actions": { |
161 | 129 | "forwardTo": [ |
162 | 130 | { |
163 | 131 | "emailAddress": { |
164 | 132 | "name": "Alex Reed", |
165 | | - "address": "coding.sigma@gmail.com" |
| 133 | + "address": "coding.sigma@gmail.com", |
166 | 134 | } |
167 | 135 | } |
168 | 136 | ], |
169 | | - "stopProcessingRules": True |
170 | | - } |
| 137 | + "stopProcessingRules": True, |
| 138 | + }, |
171 | 139 | } |
172 | 140 | ) |
173 | 141 |
|
|
0 commit comments