# EmailMessage type


An e-mail as it was sent. It is rendered once, when it is sent, and never again.

#### Who may read it

- Requires the `email.read` permission (otherwise `FORBIDDEN_ROLE` naming it).
- Requires every permission the message's content needed when it was sent: for example
  `invoice.read` for an invoice's data or document, `price.read` for amounts, `partner.read` for a
  customer's name, address or e-mail, `shipment.read` for a shipment's data and `order.read` for
  an order's data or document.
- Requires the read permission of each kind of record the message is linked to.
- Requires every record the message is linked to (the resource, an invoice's orders, a
  shipment's order, an attachment's invoice or order) to be in your API key's scope. An order,
  also a shipment's or an invoice's, counts as in your API key's scope only with `partner.read`,
  in the partner scope, and while its customer is not erased.
- A message linked to nothing is read by an API key without a scope, or by the API key that sent
  it.
- A message your API key may not read is `NOT_FOUND`, and a list leaves it out.

## Fields

### id

[`UUID!`](/chameleoon-max/type/uuid)

The message's MAX id.

### status

[`EmailMessageStatus!`](/chameleoon-max/type/email-message-status)

Where the message is on its way out.

### senderId

[`UUID!`](/chameleoon-max/type/uuid)

The MAX id of the sender the message went through.

### fromAddress

`String!`

The From address.

### fromName

`String!`

The From display name.

### replyTo

`String`

The Reply-To address. Null when the sender has none.

### to

`[String!]`

The recipients. Null only in the `sendEmail` result for an API key that may not read the
message, and so are `cc`, `bcc`, `subject`, `htmlBody` and `textBody`. No error comes with these
nulls.

Priced as 5 addresses, however many it holds (`to`, `cc` and `bcc` hold at most 50 together).

Costs 5 points.

### cc

`[String!]`

The copy recipients.

Priced as 5 addresses, however many it holds.

Costs 5 points.

### bcc

`[String!]`

The blind copy recipients.

Priced as 5 addresses, however many it holds.

Costs 5 points.

### subject

`String`

The rendered subject.

### htmlBody

`String`

The rendered HTML.

Costs 50 points.

### textBody

`String`

The rendered plain text.

Costs 50 points.

### templateCode

`String`

The code of the template the message was written with. Null when the subject and body were given.

### language

`String!`

The language the message was rendered in.

### variantLanguage

`String`

The language of the template variant the message was written with. Null for the all-languages
variant, or when there was no template.

### isTest

`Boolean!`

Whether the message was sent by [`sendTestEmail`](/chameleoon-max/mutation/send-test-email).

### attempts

`Int!`

The number of delivery attempts made.

### lastError

`String`

The MAX classification of the last failure and the provider's code, never the provider's text.
`DELIVERY_UNCERTAIN` means an attempt was cut off after it may have reached the provider, so the
message is not sent again.

### providerMessageId

`String`

The e-mail provider's id for the message. Null until it is sent.

### queuedAt

[`Time!`](/chameleoon-max/type/time)

When the message was queued.

### sentAt

[`Time`](/chameleoon-max/type/time)

When the provider accepted the message. Null until it is sent.

### failedAt

[`Time`](/chameleoon-max/type/time)

When delivery failed for good. Null unless it failed.

### links

[`EmailMessageLinkConnection`](/chameleoon-max/type/email-message-link-connection)

Arguments:

- `first`: `Int`
- `after`: `String`
- `last`: `Int`
- `before`: `String`

The records the message is linked to.

- A connection, paged with `first`/`after` or `last`/`before`, at most 250 a page.
- Its cursors belong to this message's links and are refused anywhere else.
- Null, with an error at its path, when its page cannot be read, for example because of a
  cursor of another parent, or in the `sendEmail` result for an API key that may not read the
  message (`NOT_FOUND`). The rest of the response is returned.
- A page costs 2 + first (or last) × the cost of one node.

### attachments

[`EmailMessageAttachmentConnection`](/chameleoon-max/type/email-message-attachment-connection)

Arguments:

- `first`: `Int`
- `after`: `String`
- `last`: `Int`
- `before`: `String`

The message's attachments, by position.

- A connection, paged with `first`/`after` or `last`/`before`, at most 250 a page.
- Its cursors belong to this message's attachments and are refused anywhere else.
- Null, with an error at its path, when its page cannot be read, for example because of a
  cursor of another parent, or in the `sendEmail` result for an API key that may not read the
  message (`NOT_FOUND`). The rest of the response is returned.
- A page costs 2 + first (or last) × the cost of one node.

## Used by

- [`emailMessage`](/chameleoon-max/query/email-message) (query)
- [`EmailMessageConnection`](/chameleoon-max/type/email-message-connection)
- [`EmailMessageEdge`](/chameleoon-max/type/email-message-edge)
- [`SendEmailResult`](/chameleoon-max/type/send-email-result)
