# Send messages with Python

Source: https://developer.nylas.com/docs/v3/sdks/python/send-email/

This page explains how to send messages with the Nylas Python SDK and Email API.

## Before you begin

Before you start, you must have done the following tasks:

- [Installed and set up the Nylas Python SDK](/docs/v3/sdks/python/).
- Authenticated one or more users.

## Create and send a draft

To create a draft and send it as a message, first create a Draft object and assign it attributes.

```python
draft = nylas.drafts.create(
    grant_id,
    request_body={
      "to": [{ "name": "Recipient Name", "email": "name@example.com" }],
      "reply_to": [{ "name": "Reply Name", "email": "reply@example.com" }],
      "subject": "Your Subject Here",
      "body": "Your email body here.",
    }
)
```

The `to` parameter is an array of email objects that contains names and email addresses. You can use `to` for `cc` and `bcc`.

Next, use `drafts.send()` to send the draft as a message.

```python
draft = nylas.drafts.send(
  '<NYLAS_GRANT_ID>',
  '<DRAFT_ID>',
)
```

## Reply to a message

The first step to reply to a message is to find the thread you want to reply to. Then, create a draft that has the same `thread_id` and `subject`, as in the following example.

```python
from dotenv import load_dotenv
load_dotenv()


from nylas import Client

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

draft = nylas.drafts.create(
    '<NYLAS_GRANT_ID>',
    request_body={
      "to": [{ "name": "Recipient Name", "email": "name@example.com" }],
      "reply_to": [{ "name": "Reply Name", "email": "reply@example.com" }],
      "subject": "Your Subject Here",
      "body": "Your email body here.",
      "thread_id": '<THREAD_ID>'
    }
)

draft_sent = nylas.drafts.send(
    '<NYLAS_GRANT_ID>',
    draft.data.id,
)
```

## Attach a file to a message

The [Attachments endpoint](/docs/reference/api/attachments/) allows you to create and modify files that you can attach to messages. The following example shows how to take a file that's saved locally and upload it to Nylas for use with the Email API.

```python
from nylas.utils.file_utils import attach_file_request_builder

# Attachment to add to draft
attachment = attach_file_request_builder('attachment.pdf')
```

Next, create a draft to attach the file to.

```python
draft = nylas.drafts.create(
    '<NYLAS_GRANT_ID>',
    request_body={
      "to": [{ "name": "Recipient Name", "email": "name@example.com" }],
      "reply_to": [{ "name": "Reply Name", "email": "reply@example.com" }],
      "subject": "Your Subject Here",
      "body": "Your email body here.",
      "attachments": [attachment]
    }
)

draft_sent = nylas.drafts.send(
    '<NYLAS_GRANT_ID>',
    draft.data.id,
)
```

Below is the full example showing how to attach a file to a message.

```python
from dotenv import load_dotenv
load_dotenv()


from nylas import Client
from nylas.utils.file_utils import attach_file_request_builder

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

attachment = attach_file_request_builder('attachment.pdf')

draft = nylas.drafts.create(
    '<NYLAS_GRANT_ID>',
    request_body={
      "to": [{ "name": "Recipient Name", "email": "name@example.com" }],
      "reply_to": [{ "name": "Reply Name", "email": "reply@example.com" }],
      "subject": "Your Subject Here",
      "body": "Your email body here.",
      "attachments": [attachment]
    }
)

draft_sent = nylas.drafts.send(
    '<NYLAS_GRANT_ID>',
    draft.data.id,
)
```