# Create an Email activity

POST https://api.close.com/api/v1/activity/email/
Content-Type: application/json

*status* must be one of the following:

 - `inbox` to log an already received email.
 - `draft` to create a draft email.
 - `scheduled` to send an email at a scheduled date and time, which must be specified in the `date_scheduled` field.
 - `outbox` to actually **send** an email. To delay email sending by a few seconds (to allow undo), specify `send_in` in seconds (must be less than 60).
 - `sent` to log an already sent email.

Only drafts can be modified, and their status can be changed to `scheduled` (to send later) or `outbox` (to send immediately). Scheduled emails, or emails in outbox that weren't sent yet can be canceled by setting the status back to `draft`.

For scheduled, outbox, or sent emails, a `followup_date` may be posted, which will have Close create an email followup task if no response was received.

We'll render an Email Template server-side if you include a `template_id` _without_ including `body_text` or `body_html` in your POST.

To specify both a sender name and a sender email address when posting an email, you can use the `sender` field with the format `"sender": ""John Smith" <emailaddress@example.com>"`

The `sender` field is **required** for emails with status `inbox`, `scheduled`, `outbox`, or `error`. It may be omitted for `draft` (since the sender can be specified later before sending) and `sent` (where it defaults to the email address of the `user` associated with the email or the owner of the API key).

To include an attachment, you must first upload the file to Close using the [Files API](/resources/files/). Then, add an object to the `attachments` array with the following fields: `url`, `filename`, `content_type`, and `size`. The `url` should be the URL provided in the `download.url` field of the response from the [Files API](/resources/files/). It must begin `https://app.close.com/go/file/`.

Reference: https://developer.close.com/api/resources/activities/emails/create

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Close API
  version: 1.0.0
paths:
  /activity/email/:
    post:
      operationId: create
      summary: Create an Email activity
      description: >-
        *status* must be one of the following:

         - `inbox` to log an already received email.
         - `draft` to create a draft email.
         - `scheduled` to send an email at a scheduled date and time, which must be specified in the `date_scheduled` field.
         - `outbox` to actually **send** an email. To delay email sending by a few seconds (to allow undo), specify `send_in` in seconds (must be less than 60).
         - `sent` to log an already sent email.

        Only drafts can be modified, and their status can be changed to
        `scheduled` (to send later) or `outbox` (to send immediately). Scheduled
        emails, or emails in outbox that weren't sent yet can be canceled by
        setting the status back to `draft`.


        For scheduled, outbox, or sent emails, a `followup_date` may be posted,
        which will have Close create an email followup task if no response was
        received.


        We'll render an Email Template server-side if you include a
        `template_id` _without_ including `body_text` or `body_html` in your
        POST.


        To specify both a sender name and a sender email address when posting an
        email, you can use the `sender` field with the format `"sender": ""John
        Smith" <emailaddress@example.com>"`


        The `sender` field is **required** for emails with status `inbox`,
        `scheduled`, `outbox`, or `error`. It may be omitted for `draft` (since
        the sender can be specified later before sending) and `sent` (where it
        defaults to the email address of the `user` associated with the email or
        the owner of the API key).


        To include an attachment, you must first upload the file to Close using
        the [Files API](/resources/files/). Then, add an object to the
        `attachments` array with the following fields: `url`, `filename`,
        `content_type`, and `size`. The `url` should be the URL provided in the
        `download.url` field of the response from the [Files
        API](/resources/files/). It must begin `https://app.close.com/go/file/`.
      tags:
        - subpackage_activitiesEmails
      parameters:
        - name: Authorization
          in: header
          description: Basic authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EmailActivity'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                description: Any type
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                description: Any type
        '404':
          description: Not found
          content:
            application/json:
              schema:
                description: Any type
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateEmailActivity'
servers:
  - url: https://api.close.com/api/v1
components:
  schemas:
    CreateEmailActivityAttachmentsItems:
      type: object
      properties:
        content_id:
          type:
            - string
            - 'null'
        content_type:
          type:
            - string
            - 'null'
        filename:
          type: string
        inline_only:
          type: boolean
        size:
          type: integer
        url:
          type: string
          format: uri
      required:
        - filename
        - size
        - url
      title: CreateEmailActivityAttachmentsItems
    CreateEmailActivityOpensItems:
      type: object
      properties:
        opened_at:
          type: string
          format: date-time
      required:
        - opened_at
      title: CreateEmailActivityOpensItems
    CreateEmailActivityStatus:
      type: string
      enum:
        - inbox
        - draft
        - scheduled
        - outbox
        - sent
        - error
      title: CreateEmailActivityStatus
    CreateEmailActivity:
      type: object
      properties:
        account_id:
          type:
            - string
            - 'null'
        activity_at:
          type:
            - string
            - 'null'
          format: date-time
        attachments:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/CreateEmailActivityAttachmentsItems'
        bcc:
          type:
            - array
            - 'null'
          items:
            type: string
        body_html:
          type:
            - string
            - 'null'
        body_text:
          type:
            - string
            - 'null'
        cc:
          type:
            - array
            - 'null'
          items:
            type: string
        contact_id:
          type:
            - string
            - 'null'
        created_by_id:
          type:
            - string
            - 'null'
        date_created:
          type:
            - string
            - 'null'
          format: date-time
        followup_date:
          type:
            - string
            - 'null'
          format: date-time
        followup_sequence_add_cc_bcc:
          type:
            - boolean
            - 'null'
        followup_sequence_delay:
          type:
            - integer
            - 'null'
        followup_sequence_id:
          type:
            - string
            - 'null'
        in_reply_to_id:
          type:
            - string
            - 'null'
        lead_id:
          type: string
        opens:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/CreateEmailActivityOpensItems'
        organization_id:
          type:
            - string
            - 'null'
        sender:
          type:
            - string
            - 'null'
          format: email
        status:
          $ref: '#/components/schemas/CreateEmailActivityStatus'
        subject:
          type:
            - string
            - 'null'
        template_id:
          type:
            - string
            - 'null'
        to:
          type:
            - array
            - 'null'
          items:
            type: string
        user_id:
          type:
            - string
            - 'null'
      required:
        - lead_id
        - status
      title: CreateEmailActivity
    Attachment:
      type: object
      properties:
        content_type:
          type:
            - string
            - 'null'
        filename:
          type:
            - string
            - 'null'
        size:
          type:
            - integer
            - 'null'
        thumbnail_url:
          type:
            - string
            - 'null'
        url:
          type: string
      required:
        - content_type
        - filename
        - size
        - url
      title: Attachment
    CommunicationDirection:
      type: string
      enum:
        - incoming
        - outgoing
      description: >-
        This is the former EmailDirection.

        Any activity that has a concept of direction (in or out) should be using

        this enum.

        For historical reasons, this is different from PhoneActivityDirection

        but at some point PhoneActivityDirection should be deprecated and
        replaced

        with CommunicationDirection.
      title: CommunicationDirection
    MessageStatus:
      type: string
      enum:
        - inbox
        - draft
        - scheduled
        - outbox
        - sent
        - error
      description: |-
        Status of a message, such as Email or SMS.

        This set of statuses should be enough to support features such as
        "send later" or "undo send".
      title: MessageStatus
    EmailActivity:
      type: object
      properties:
        _type:
          type: string
        activity_at:
          type:
            - string
            - 'null'
          format: date-time
        agent_action_reason:
          type:
            - string
            - 'null'
        agent_config_id:
          type:
            - string
            - 'null'
        attachments:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/Attachment'
        bcc:
          type: array
          items:
            type: string
        body_html:
          type:
            - string
            - 'null'
        body_preview:
          type:
            - string
            - 'null'
        body_text:
          type:
            - string
            - 'null'
        bulk_email_action_id:
          type:
            - string
            - 'null'
        cc:
          type: array
          items:
            type: string
        contact_id:
          type:
            - string
            - 'null'
        created_by:
          type:
            - string
            - 'null'
        created_by_name:
          type:
            - string
            - 'null'
        date_created:
          type: string
          format: date-time
        date_scheduled:
          type:
            - string
            - 'null'
          format: date-time
        date_sent:
          type:
            - string
            - 'null'
          format: date-time
        date_updated:
          type: string
          format: date-time
        direction:
          oneOf:
            - $ref: '#/components/schemas/CommunicationDirection'
            - type: 'null'
        email_account_id:
          type:
            - string
            - 'null'
        envelope:
          type:
            - object
            - 'null'
          additionalProperties:
            description: Any type
        followup_sequence_add_cc_bcc:
          type: boolean
        followup_sequence_delay:
          type:
            - integer
            - 'null'
        followup_sequence_id:
          type:
            - string
            - 'null'
        has_reply:
          type: boolean
        id:
          type: string
        in_reply_to_id:
          type:
            - string
            - 'null'
        lead_id:
          type:
            - string
            - 'null'
        message_ids:
          type: array
          items:
            type: string
        need_smtp_credentials:
          type: boolean
        opens:
          type:
            - array
            - 'null'
          items:
            type: object
            additionalProperties:
              type: string
        opens_summary:
          type:
            - string
            - 'null'
        organization_id:
          type: string
        references:
          type: array
          items:
            type: string
        send_as_id:
          type:
            - string
            - 'null'
        send_attempts:
          type:
            - array
            - 'null'
          items:
            type: object
            additionalProperties:
              type: string
        sender:
          type:
            - string
            - 'null'
        sequence_id:
          type:
            - string
            - 'null'
        sequence_name:
          type:
            - string
            - 'null'
        sequence_subscription_id:
          type:
            - string
            - 'null'
        status:
          $ref: '#/components/schemas/MessageStatus'
        subject:
          type:
            - string
            - 'null'
        template_id:
          type:
            - string
            - 'null'
        template_name:
          type:
            - string
            - 'null'
        thread_id:
          type:
            - string
            - 'null'
        to:
          type: array
          items:
            type: string
        updated_by:
          type:
            - string
            - 'null'
        updated_by_name:
          type:
            - string
            - 'null'
        user_id:
          type:
            - string
            - 'null'
        user_name:
          type:
            - string
            - 'null'
        users:
          type: array
          items:
            type: string
      required:
        - _type
        - activity_at
        - bcc
        - body_html
        - body_text
        - bulk_email_action_id
        - cc
        - contact_id
        - created_by
        - date_created
        - date_scheduled
        - date_sent
        - date_updated
        - direction
        - followup_sequence_add_cc_bcc
        - followup_sequence_delay
        - has_reply
        - id
        - in_reply_to_id
        - lead_id
        - message_ids
        - need_smtp_credentials
        - opens_summary
        - organization_id
        - references
        - send_as_id
        - sender
        - status
        - subject
        - template_id
        - thread_id
        - to
        - updated_by
        - user_id
        - users
      title: EmailActivity
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: basic
    OAuth2:
      type: http
      scheme: bearer

```