Class: Telnyx::Resources::EmailMessages

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/email_messages.rb,
lib/telnyx/resources/email_messages/recipients.rb,
sig/telnyx/resources/email_messages.rbs,
sig/telnyx/resources/email_messages/recipients.rbs

Overview

Send and manage email messages. Legacy /v2/emails routes are aliases for these endpoints.

Defined Under Namespace

Classes: Recipients

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ EmailMessages

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EmailMessages.

Parameters:



288
289
290
291
# File 'lib/telnyx/resources/email_messages.rb', line 288

def initialize(client:)
  @client = client
  @recipients = Telnyx::Resources::EmailMessages::Recipients.new(client: client)
end

Instance Attribute Details

#recipientsTelnyx::Resources::EmailMessages::Recipients (readonly)

Send and manage email messages. Legacy /v2/emails routes are aliases for these endpoints.



11
12
13
# File 'lib/telnyx/resources/email_messages.rb', line 11

def recipients
  @recipients
end

Instance Method Details

#batch(messages:, sandbox_mode: nil, idempotency_key: nil, request_options: {}) ⇒ Telnyx::Models::EmailMessageBatchResponse

Some parameter documentations has been truncated, see Models::EmailMessageBatchParams for more details.

Creates up to 50 email messages in a single request.

Parameters:

  • messages (Array<Telnyx::Models::EmailMessageBatchParams::Message>)

    Body param

  • sandbox_mode (Boolean)

    Body param: Applies sandbox mode to all messages in the batch. Overrides any per

  • idempotency_key (String)

    Header param: Optional opaque, unquoted key for safely retrying the same logical

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/telnyx/resources/email_messages.rb', line 189

def batch(params)
  parsed, options = Telnyx::EmailMessageBatchParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :post,
    path: "email_messages/batch",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Telnyx::Models::EmailMessageBatchResponse,
    options: options
  )
end

#create(from:, to:, attachments: nil, bcc: nil, cc: nil, forward_of_message_id: nil, from_name: nil, group_id: nil, headers: nil, html_body: nil, ignore_suppression: nil, in_reply_to_message_id: nil, inline_css: nil, metadata: nil, reply_to: nil, reply_to_all: nil, sandbox_mode: nil, scheduled_at: nil, send_at: nil, subject: nil, tags: nil, template_id: nil, template_variables: nil, text_body: nil, tracking_settings: nil, idempotency_key: nil, request_options: {}) ⇒ Telnyx::Models::EmailInboxes::EmailMessageResponse

Some parameter documentations has been truncated, see Models::EmailMessageCreateParams for more details.

Queues, schedules, or sandbox-sends an email message. The legacy /v2/emails POST route is a backward-compatible alias for this operation.

subject is required unless template_id is supplied. When using template_id, do not also provide subject, html_body, or text_body; the template is rendered with template_variables.

Note: template lookup failures (not found, wrong account) return 400, not 404.

Parameters:

  • from (String, Telnyx::Models::EmailInboxes::EmailAddress)

    Body param

  • to (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • attachments (Array<Telnyx::Models::AttachmentRequest>)

    Body param

  • bcc (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • cc (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • forward_of_message_id (String, nil)

    Body param: Telnyx message UUID of the message this send forwards. Forwarded

  • from_name (String)

    Body param: Optional display name for string from; overrides from.name when

  • group_id (String, nil)

    Body param: Optional unsubscribe-group UUID used for group-scoped suppression ch

  • headers (Hash{Symbol=>String})

    Body param: Custom email headers. Write-only; not returned in responses.

  • html_body (String)

    Body param: HTML email body. Returned only by GET /email_messages/{id}; omitte

  • ignore_suppression (Boolean)

    Body param: When true, allows delivery to recipients whose suppressions explicit

  • in_reply_to_message_id (String, nil)

    Body param: Telnyx message UUID of the message this send replies to. When provid

  • inline_css (Boolean)

    Body param

  • metadata (Hash{Symbol=>Object})

    Body param: Custom metadata. Write-only; not returned in responses.

  • reply_to (String, Telnyx::Models::EmailInboxes::EmailAddress)

    Body param: Reply-to address. If provided as an object with a name, only the ema

  • reply_to_all (Boolean, nil)

    Body param: Indicates a reply-all intent. In Phase 1 (wire-only) this does not

  • sandbox_mode (Boolean)

    Body param

  • scheduled_at (Time, nil)

    Body param: Future ISO 8601 time to schedule sending. Invalid or past timestamps

  • send_at (Time)

    Body param: Deprecated alias for scheduled_at.

  • subject (String)

    Body param: Required unless template_id is supplied. When using a template, th

  • tags (Array<String>)

    Body param: Tags for categorization and reporting. Stored on the message and pro

  • template_id (String)

    Body param

  • template_variables (Hash{Symbol=>Object})

    Body param: Variables for Liquid template rendering. Non-object values may cause

  • text_body (String)

    Body param: Plain text email body. Returned only by GET /email_messages/{id};

  • tracking_settings (Telnyx::Models::TrackingSettings)

    Body param: Per-send open and click tracking overrides. Omitted properties inher

  • idempotency_key (String)

    Header param: Optional opaque, unquoted key for safely retrying the same logical

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/telnyx/resources/email_messages.rb', line 84

def create(params)
  parsed, options = Telnyx::EmailMessageCreateParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :post,
    path: "email_messages",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Telnyx::EmailInboxes::EmailMessageResponse,
    options: options
  )
end

#delete(id, request_options: {}) ⇒ nil

Permanently deletes an account-scoped email message, its events, its durable recipients, and unshared attachment objects. Returns 404 when the message does not exist in the authenticated account. The legacy /v2/emails/{id} DELETE route is a backward-compatible alias.

Parameters:

  • id (String)

    Email message UUID.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)
  • request_options: (Telnyx::request_opts)

Returns:

  • (nil)

See Also:



162
163
164
165
166
167
168
169
# File 'lib/telnyx/resources/email_messages.rb', line 162

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["email_messages/%1$s", id],
    model: NilClass,
    options: params[:request_options]
  )
end

#delete_all(address:, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::EmailMessageDeleteAllParams for more details.

Permanently deletes every email in the authenticated account sent from or to the supplied address, including retained events whose parent message has expired. Events and durable recipients are deleted immediately with each message. The operation never searches or reports matches in another account. The legacy /v2/emails DELETE route is a backward-compatible alias.

Parameters:

  • address (String)

    Sender or recipient address to delete. Matching is trimmed and case-insensitive.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



220
221
222
223
224
225
226
227
228
229
230
# File 'lib/telnyx/resources/email_messages.rb', line 220

def delete_all(params)
  parsed, options = Telnyx::EmailMessageDeleteAllParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :delete,
    path: "email_messages",
    query: query,
    model: NilClass,
    options: options
  )
end

#delete_schedule(email_id, request_options: {}) ⇒ Telnyx::Models::EmailInboxes::EmailMessageResponse

Cancels a scheduled email and returns it with status cancelled. The legacy /v2/emails/{id}/schedule DELETE route is an alias.

Parameters:

  • email_id (String)

    Email message UUID.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



244
245
246
247
248
249
250
251
# File 'lib/telnyx/resources/email_messages.rb', line 244

def delete_schedule(email_id, params = {})
  @client.request(
    method: :delete,
    path: ["email_messages/%1$s/schedule", email_id],
    model: Telnyx::EmailInboxes::EmailMessageResponse,
    options: params[:request_options]
  )
end

#list(page_cursor: nil, page_size: nil, request_options: {}) ⇒ Telnyx::Models::EmailMessageListResponse

Some parameter documentations has been truncated, see Models::EmailMessageListParams for more details.

Lists messages sorted newest first by created_at desc, id desc. No filters other than cursor pagination are implemented. The legacy /v2/emails GET route is a backward-compatible alias for this operation.

Parameters:

  • page_cursor (String)

    Opaque URL-safe Base64 cursor returned by a previous list response.

  • page_size (Integer)

    Number of results to return. Defaults to 25; maximum is 100. Invalid values are

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/telnyx/resources/email_messages.rb', line 136

def list(params = {})
  parsed, options = Telnyx::EmailMessageListParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "email_messages",
    query: query,
    model: Telnyx::Models::EmailMessageListResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ Telnyx::Models::EmailMessageRetrieveResponse

The legacy /v2/emails/{id} GET route is a backward-compatible alias for this operation.

Parameters:

Returns:

See Also:



109
110
111
112
113
114
115
116
# File 'lib/telnyx/resources/email_messages.rb', line 109

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["email_messages/%1$s", id],
    model: Telnyx::Models::EmailMessageRetrieveResponse,
    options: params[:request_options]
  )
end

#retrieve_events(email_id, page_cursor: nil, page_size: nil, request_options: {}) ⇒ Telnyx::Models::EmailMessageRetrieveEventsResponse

Some parameter documentations has been truncated, see Models::EmailMessageRetrieveEventsParams for more details.

Lists events for a single message sorted oldest first by occurred_at asc, id asc. The legacy /v2/emails/{id}/events GET route is a backward-compatible alias.

Parameters:

  • email_id (String)

    Email message UUID.

  • page_cursor (String)

    Opaque URL-safe Base64 cursor returned by a previous list response.

  • page_size (Integer)

    Number of results to return. Defaults to 25; maximum is 100. Invalid values are

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



273
274
275
276
277
278
279
280
281
282
283
# File 'lib/telnyx/resources/email_messages.rb', line 273

def retrieve_events(email_id, params = {})
  parsed, options = Telnyx::EmailMessageRetrieveEventsParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["email_messages/%1$s/events", email_id],
    query: query,
    model: Telnyx::Models::EmailMessageRetrieveEventsResponse,
    options: options
  )
end