Skip to content

Instantly share code, notes, and snippets.

@waterswv
Created April 18, 2018 18:48
Show Gist options
  • Save waterswv/a9a995c2d33693fa3a69fa00f497013e to your computer and use it in GitHub Desktop.
Save waterswv/a9a995c2d33693fa3a69fa00f497013e to your computer and use it in GitHub Desktop.
Python SDK Challenge
#!/usr/bin/env python
from nylas import APIClient
import json
config = json.load(open('config.json'))
def main():
client = APIClient(config['NYLAS_APP_ID'], config['NYLAS_APP_SECRET'], config['NYLAS_ACCESS_TOKEN'])
message_arr = []
# Get 10 threads from lars@metafoo.de
for thread in client.threads.where(any_email='lars@metafoo.de', limit='10'):
# Print out the subject of each of those threads
print(thread.subject)
message_arr.extend(thread.message_ids)
# Send a message to mike@nylas.com. The body should include all message_ids of
msg = ''
for i in message_arr:
msg = msg + i + ','
# the threads from above.
# Create a new draft
draft = client.drafts.create()
draft.to = [{'name': 'My Friend', 'email': 'mike@nylas.com'}]
draft.subject = "Here are the ids"
draft.body = msg
try:
draft.send()
except nylas.client.errors.ConnectionError as e:
print("Unable to connect to the SMTP server.")
except nylas.client.errors.MessageRejectedError as e:
print("Message got rejected by the SMTP server!")
print(e.message)
# Print the Message-ID Header in the message you just sent
message = client.messages.where(subject='Here are the ids', limit='1', view='expanded')
print(message.headers['Message-Id'])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment