---
title: "POST /users/{userId}/messages/import"
method: POST
path: "/users/{userId}/messages/import"
tags: ["users"]
---

# POST /users/{userId}/messages/import

`POST /users/{userId}/messages/import`

Imports a message into only this user's mailbox, with standard email delivery scanning and classification similar to receiving via SMTP. This method doesn't perform SPF checks, so it might not work for some spam messages, such as those attempting to perform domain spoofing. This method does not send a message.

## Path parameters

- `userId` string, required

## Query parameters

- `$.xgafv` '1' | '2' — V1 error format
- `access_token` string
- `alt` 'json' | 'media' | 'proto' — Data format for response
- `callback` string
- `fields` string
- `key` string
- `oauth_token` string
- `prettyPrint` boolean
- `quotaUser` string
- `upload_protocol` string
- `uploadType` string
- `deleted` boolean
- `internalDateSource` 'receivedTime' | 'dateHeader'
- `neverMarkSpam` boolean
- `processForCalendar` boolean

## Request body

- Message — An email message
  - `snippet` string — A short part of the message text
  - `threadId` string — The ID of the thread the message belongs to. To add a message or draft to a thread, the following criteria must be met: 1. The requested `threadId` must be specified on the `Message` or `Draft.Message` you supply with your request. 2. The `References` and `In-Reply-To` headers must be set in compliance with the [RFC 2822](https://tools.ietf.org/html/rfc2822) standard. 3. The `Subject` headers must match.
  - `labelIds` string[] — List of IDs of labels applied to this message
  - `payload` MessagePart — A single MIME message part
    - `headers` MessagePartHeader[] — List of headers on this message part. For the top-level message part, representing the entire message payload, it will contain the standard RFC 2822 email headers such as `To`, `From`, and `Subject`
      - `name` string — The name of the header before the `:` separator. For example, `To`
      - `value` string — The value of the header after the `:` separator. For example, `someuser@example.com`
    - `filename` string — The filename of the attachment. Only present if this message part represents an attachment
    - `partId` string — The immutable ID of the message part
    - `parts` MessagePart[] — The child MIME message parts of this part. This only applies to container MIME message parts, for example `multipart/*`. For non- container MIME message part types, such as `text/plain`, this field is empty. For more information, see RFC 1521
    - `mimeType` string — The MIME type of the message part
    - `body` MessagePartBody — The body of a single MIME message part
      - `data` string, byte — The body data of a MIME message part as a base64url encoded string. May be empty for MIME container types that have no message body or when the body data is sent as a separate attachment. An attachment ID is present if the body data is contained in a separate attachment
      - `size` integer — Number of bytes for the message part data (encoding notwithstanding)
      - `attachmentId` string — When present, contains the ID of an external attachment that can be retrieved in a separate `messages.attachments.get` request. When not present, the entire content of the message part body is contained in the data field
  - `historyId` string, uint64 — The ID of the last history record that modified this message
  - `raw` string, byte — The entire email message in an RFC 2822 formatted and base64url encoded string. Returned in `messages.get` and `drafts.get` responses when the `format=RAW` parameter is supplied
  - `id` string — The immutable ID of the message
  - `sizeEstimate` integer — Estimated size in bytes of the message
  - `internalDate` string, int64 — The internal message creation timestamp (epoch ms), which determines ordering in the inbox. For normal SMTP-received email, this represents the time the message was originally accepted by Google, which is more reliable than the `Date` header. However, for API-migrated mail, it can be configured by client to be based on the `Date` header

## Response `200`

Successful response

- Message — An email message
  - `snippet` string — A short part of the message text
  - `threadId` string — The ID of the thread the message belongs to. To add a message or draft to a thread, the following criteria must be met: 1. The requested `threadId` must be specified on the `Message` or `Draft.Message` you supply with your request. 2. The `References` and `In-Reply-To` headers must be set in compliance with the [RFC 2822](https://tools.ietf.org/html/rfc2822) standard. 3. The `Subject` headers must match.
  - `labelIds` string[] — List of IDs of labels applied to this message
  - `payload` MessagePart — A single MIME message part
    - `headers` MessagePartHeader[] — List of headers on this message part. For the top-level message part, representing the entire message payload, it will contain the standard RFC 2822 email headers such as `To`, `From`, and `Subject`
      - `name` string — The name of the header before the `:` separator. For example, `To`
      - `value` string — The value of the header after the `:` separator. For example, `someuser@example.com`
    - `filename` string — The filename of the attachment. Only present if this message part represents an attachment
    - `partId` string — The immutable ID of the message part
    - `parts` MessagePart[] — The child MIME message parts of this part. This only applies to container MIME message parts, for example `multipart/*`. For non- container MIME message part types, such as `text/plain`, this field is empty. For more information, see RFC 1521
    - `mimeType` string — The MIME type of the message part
    - `body` MessagePartBody — The body of a single MIME message part
      - `data` string, byte — The body data of a MIME message part as a base64url encoded string. May be empty for MIME container types that have no message body or when the body data is sent as a separate attachment. An attachment ID is present if the body data is contained in a separate attachment
      - `size` integer — Number of bytes for the message part data (encoding notwithstanding)
      - `attachmentId` string — When present, contains the ID of an external attachment that can be retrieved in a separate `messages.attachments.get` request. When not present, the entire content of the message part body is contained in the data field
  - `historyId` string, uint64 — The ID of the last history record that modified this message
  - `raw` string, byte — The entire email message in an RFC 2822 formatted and base64url encoded string. Returned in `messages.get` and `drafts.get` responses when the `format=RAW` parameter is supplied
  - `id` string — The immutable ID of the message
  - `sizeEstimate` integer — Estimated size in bytes of the message
  - `internalDate` string, int64 — The internal message creation timestamp (epoch ms), which determines ordering in the inbox. For normal SMTP-received email, this represents the time the message was originally accepted by Google, which is more reliable than the `Date` header. However, for API-migrated mail, it can be configured by client to be based on the `Date` header

---

[API](https://skmtc.net/ballerina-platform/apis/gmail-api.md) · [All operations](https://skmtc.net/ballerina-platform/apis/gmail-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/ballerina-platform/gmail-api/versions/c7f11764507c/schema)
