Skip to content

Commit

Permalink
Merge pull request googleapis#99 from hellbe/master
Browse files Browse the repository at this point in the history
Added support for sending from shared mailbox
  • Loading branch information
Narcolapser authored Jul 3, 2018
2 parents e15b794 + 85c723e commit 9ef3698
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
15 changes: 12 additions & 3 deletions O365/fluent_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'

Expand Down Expand Up @@ -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'}

Expand All @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 9ef3698

Please sign in to comment.