forked from nylas/nylas-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_files_in_dir.py
More file actions
executable file
·35 lines (28 loc) · 942 Bytes
/
upload_files_in_dir.py
File metadata and controls
executable file
·35 lines (28 loc) · 942 Bytes
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
#!/usr/bin/python
import os
import time
from nylas import APIClient
from nylas.util import generate_id
APP_ID = '[YOUR_APP_ID]'
APP_SECRET = '[YOUR_APP_SECRET]'
ACCESS_TOKEN = '[YOUR_ACCESS_TOKEN]'
client = APIClient(APP_ID, APP_SECRET, ACCESS_TOKEN)
subject = generate_id()
# Create a new draft
draft = client.drafts.create()
draft.to = [{'name': 'Nylas PythonSDK', 'email': 'nylastestempty@gmail.com'}]
draft.subject = subject
draft.body = ""
for filename in filter(lambda x: not os.path.isdir(x), os.listdir(".")):
f = open(filename, 'r')
attachment = client.files.create()
attachment.filename = filename
attachment.stream = f
attachment.save()
draft.attach(attachment)
draft.send()
th = client.threads.where({'in': 'Sent', 'subject': subject}).first()
while not th:
time.sleep(0.5)
th = client.threads.where({'in': 'Sent', 'subject': subject}).first()
print th.messages[0].attachments[0].download()