Skip to content

Commit 9ef3698

Browse files
authored
Merge pull request googleapis#99 from hellbe/master
Added support for sending from shared mailbox
2 parents e15b794 + 85c723e commit 9ef3698

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

O365/fluent_message.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Message(object):
4141

4242
att_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}/attachments'
4343
send_url = 'https://outlook.office365.com/api/v1.0/me/sendmail'
44+
send_as_url = 'https://outlook.office365.com/api/v1.0/users/{user_id}/sendmail'
4445
draft_url = 'https://outlook.office365.com/api/v1.0/me/folders/{folder_id}/messages'
4546
update_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}'
4647

@@ -89,8 +90,12 @@ def fetchAttachments(self,**kwargs):
8990

9091
return len(self.attachments)
9192

92-
def sendMessage(self, **kwargs):
93-
'''takes local variabls and forms them into a message to be sent.'''
93+
def sendMessage(self, user_id=None, **kwargs):
94+
'''
95+
Takes local variabls and forms them into a message to be sent.
96+
97+
:param user_id: User id (email) if sending as other user
98+
'''
9499

95100
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
96101

@@ -109,8 +114,12 @@ def sendMessage(self, **kwargs):
109114
'Error while trying to compile the json string to send: {0}'.format(str(e)))
110115
return False
111116

117+
if user_id:
118+
url = self.send_as_url.format(user_id=user_id)
119+
else:
120+
usl = self.send_url
112121
response = requests.post(
113-
self.send_url, data, headers=headers, auth=self.auth, verify=self.verify, **kwargs)
122+
url, data, headers=headers, auth=self.auth, verify=self.verify, **kwargs)
114123
log.debug('response from server for sending message:' + str(response))
115124
log.debug("respnse body: {}".format(response.text))
116125
if response.status_code != 202:

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if m.json['IsReadReceiptRequested']:
3434
## Email
3535
There are two classes for working with emails in O365.
3636
#### Inbox
37-
A collection of emails. This is used when ever you are requesting an email or emails. It can be set with filters so that you only download the emails which your script is interested in.
37+
A collection of emails. This is used when ever you are requesting an email or emails. It can be set with filters so that you only download the emails which your script is interested in.
3838
#### Message
3939
An actual email with all it's associated data.
4040

@@ -180,7 +180,7 @@ Connection.oauth2("your client_id", "your client_secret", store_token=True)
180180
# Proxy call is required only if you are behind proxy
181181
Connection.proxy(url='proxy.company.com', port=8080, username='proxy_username', password='proxy_password')
182182
```
183-
183+
184184

185185

186186
## Fluent Inbox
@@ -222,4 +222,11 @@ for message in inbox.search('Category:some_cat').skip(1).fetch(1):
222222
inbox.fetch_first(10)
223223
```
224224

225+
### Support for shared mailboxes
226+
Basic support for working with shared mailboxes exists. The following functions take `user_id` as a keyword argument specifying the email address of the shared mailbox.
227+
228+
* `FluentInbox.from_folder(..)` - read messages messages
229+
* `FluentInbox.get_folder(..)` - list folders
230+
* `FluentMessage.sendMessage(..)` - send as shared mailbox
231+
225232
#### Soli Deo Gloria

0 commit comments

Comments
 (0)