diff --git a/O365/fluent_message.py b/O365/fluent_message.py index 164ea6061e14e..9bbd55461981a 100644 --- a/O365/fluent_message.py +++ b/O365/fluent_message.py @@ -41,6 +41,7 @@ class Message(object): att_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}/attachments' send_url = 'https://outlook.office365.com/api/v1.0/me/sendmail' + send_as_url = 'https://outlook.office365.com/api/v1.0/users/{user_id}/sendmail' draft_url = 'https://outlook.office365.com/api/v1.0/me/folders/{folder_id}/messages' update_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}' @@ -89,8 +90,12 @@ def fetchAttachments(self,**kwargs): return len(self.attachments) - def sendMessage(self, **kwargs): - '''takes local variabls and forms them into a message to be sent.''' + def sendMessage(self, user_id=None, **kwargs): + ''' + Takes local variabls and forms them into a message to be sent. + + :param user_id: User id (email) if sending as other user + ''' headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} @@ -109,8 +114,12 @@ def sendMessage(self, **kwargs): 'Error while trying to compile the json string to send: {0}'.format(str(e))) return False + if user_id: + url = self.send_as_url.format(user_id=user_id) + else: + usl = self.send_url response = requests.post( - self.send_url, data, headers=headers, auth=self.auth, verify=self.verify, **kwargs) + url, data, headers=headers, auth=self.auth, verify=self.verify, **kwargs) log.debug('response from server for sending message:' + str(response)) log.debug("respnse body: {}".format(response.text)) if response.status_code != 202: diff --git a/README.md b/README.md index b793d74a816ce..88a87703cf1f3 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ if m.json['IsReadReceiptRequested']: ## Email There are two classes for working with emails in O365. #### Inbox -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. +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. #### Message An actual email with all it's associated data. @@ -180,7 +180,7 @@ Connection.oauth2("your client_id", "your client_secret", store_token=True) # Proxy call is required only if you are behind proxy Connection.proxy(url='proxy.company.com', port=8080, username='proxy_username', password='proxy_password') ``` - + ## Fluent Inbox @@ -222,4 +222,11 @@ for message in inbox.search('Category:some_cat').skip(1).fetch(1): inbox.fetch_first(10) ``` +### Support for shared mailboxes +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. + +* `FluentInbox.from_folder(..)` - read messages messages +* `FluentInbox.get_folder(..)` - list folders +* `FluentMessage.sendMessage(..)` - send as shared mailbox + #### Soli Deo Gloria