// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as SubdomainsAPI from './subdomains/subdomains'; import { BaseSubdomains, SubdomainCreateParams, SubdomainCreateResponse, SubdomainDeleteParams, SubdomainDeleteResponse, SubdomainGetParams, SubdomainGetResponse, SubdomainListParams, SubdomainListResponse, SubdomainListResponsesSinglePage, Subdomains, } from './subdomains/subdomains'; import { APIPromise } from '../../core/api-promise'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class BaseEmailSending extends APIResource { static override readonly _key: readonly ['emailSending'] = Object.freeze(['emailSending'] as const); /** * Send an email for the specified account using the structured builder. Provide * the sender, recipients, subject, and at least one of text or html; attachments * are optional. * * @example * ```ts * const response = await client.emailSending.send({ * account_id: 'account_id', * from: 'sender@example.com', * subject: 'Monthly Report', * }); * ``` */ send(params: EmailSendingSendParams, options?: RequestOptions): APIPromise { const { account_id, ...body } = params; return ( this._client.post(path`/accounts/${account_id}/email/sending/send`, { body, ...options, }) as APIPromise<{ result: EmailSendingSendResponse }> )._thenUnwrap((obj) => obj.result); } /** * Send a raw RFC 5322 (MIME) email for the specified account. Provide the full * MIME message plus the SMTP envelope (from and recipients). * * @example * ```ts * const response = await client.emailSending.sendRaw({ * account_id: 'account_id', * from: 'sender@example.com', * mime_message: * 'From: sender@example.com\r\nTo: recipient@example.com\r\nSubject: Hello\r\nContent-Type: text/plain\r\n\r\nHello, World!', * recipients: ['recipient@example.com'], * }); * ``` */ sendRaw( params: EmailSendingSendRawParams, options?: RequestOptions, ): APIPromise { const { account_id, ...body } = params; return ( this._client.post(path`/accounts/${account_id}/email/sending/send_raw`, { body, ...options, }) as APIPromise<{ result: EmailSendingSendRawResponse }> )._thenUnwrap((obj) => obj.result); } } export class EmailSending extends BaseEmailSending { subdomains: SubdomainsAPI.Subdomains = new SubdomainsAPI.Subdomains(this._client); } export interface EmailSendingSendResponse { /** * Email addresses to which the message was delivered immediately. */ delivered: Array; /** * Message ID of the sent email. */ message_id: string; /** * Email addresses that permanently bounced. */ permanent_bounces: Array; /** * Email addresses for which delivery was queued for later. */ queued: Array; } export interface EmailSendingSendRawResponse { /** * Email addresses to which the message was delivered immediately. */ delivered: Array; /** * Message ID of the sent email. */ message_id: string; /** * Email addresses that permanently bounced. */ permanent_bounces: Array; /** * Email addresses for which delivery was queued for later. */ queued: Array; } export interface EmailSendingSendParams { /** * Path param: Identifier of the account. */ account_id: string; /** * Body param: Sender email address. Either a plain string or an object with * address and name. */ from: string | EmailSendingSendParams.EmailSendingEmailAddressObject; /** * Body param: Email subject line. */ subject: string; /** * Body param: File attachments and inline images. */ attachments?: Array< | EmailSendingSendParams.EmailSendingEmailInlineAttachment | EmailSendingSendParams.EmailSendingEmailAttachment >; /** * Body param: Recipient(s). Optional if cc or bcc is provided. A single email * string, a named address object, or an array of either. */ bcc?: | string | EmailSendingSendParams.EmailSendingEmailAddressObject | Array; /** * Body param: Recipient(s). Optional if cc or bcc is provided. A single email * string, a named address object, or an array of either. */ cc?: | string | EmailSendingSendParams.EmailSendingEmailAddressObject | Array; /** * Body param: Custom email headers as key-value pairs. */ headers?: { [key: string]: string }; /** * Body param: HTML body of the email. Provide at least one of text or html * (non-empty). */ html?: string; /** * Body param: Reply-to address. Either a plain string or an object with address * and name. */ reply_to?: string | EmailSendingSendParams.EmailSendingEmailAddressObject; /** * Body param: Plain text body of the email. Provide at least one of text or html * (non-empty). */ text?: string; /** * Body param: Recipient(s). Optional if cc or bcc is provided. A single email * string, a named address object, or an array of either. */ to?: | string | EmailSendingSendParams.EmailSendingEmailAddressObject | Array; } export namespace EmailSendingSendParams { export interface EmailSendingEmailAddressObject { /** * Email address (e.g., 'user@example.com'). */ address: string; /** * Display name for the email address (e.g., 'John Doe'). Optional; set to null or * leave it unset to send the address on its own. */ name?: string | null; } export interface EmailSendingEmailInlineAttachment { /** * Base64-encoded content of the attachment. */ content: string; /** * Content ID used to reference this attachment in HTML via cid: URI (e.g., * ). */ content_id: string; /** * Use 'inline' to embed the attachment in the email body. */ disposition: 'inline'; /** * Filename for the attachment. */ filename: string; /** * MIME type of the attachment (e.g., 'image/png', 'text/plain'). */ type: string; } export interface EmailSendingEmailAttachment { /** * Base64-encoded content of the attachment. */ content: string; /** * Use 'attachment' for a standard file attachment. */ disposition: 'attachment'; /** * Filename for the attachment. */ filename: string; /** * MIME type of the attachment (e.g., 'application/pdf', 'text/plain'). */ type: string; } export interface EmailSendingEmailAddressObject { /** * Email address (e.g., 'user@example.com'). */ address: string; /** * Display name for the email address (e.g., 'John Doe'). Optional; set to null or * leave it unset to send the address on its own. */ name?: string | null; } export interface EmailSendingEmailAddressObject { /** * Email address (e.g., 'user@example.com'). */ address: string; /** * Display name for the email address (e.g., 'John Doe'). Optional; set to null or * leave it unset to send the address on its own. */ name?: string | null; } export interface EmailSendingEmailAddressObject { /** * Email address (e.g., 'user@example.com'). */ address: string; /** * Display name for the email address (e.g., 'John Doe'). Optional; set to null or * leave it unset to send the address on its own. */ name?: string | null; } export interface EmailSendingEmailAddressObject { /** * Email address (e.g., 'user@example.com'). */ address: string; /** * Display name for the email address (e.g., 'John Doe'). Optional; set to null or * leave it unset to send the address on its own. */ name?: string | null; } export interface EmailSendingEmailAddressObject { /** * Email address (e.g., 'user@example.com'). */ address: string; /** * Display name for the email address (e.g., 'John Doe'). Optional; set to null or * leave it unset to send the address on its own. */ name?: string | null; } export interface EmailSendingEmailAddressObject { /** * Email address (e.g., 'user@example.com'). */ address: string; /** * Display name for the email address (e.g., 'John Doe'). Optional; set to null or * leave it unset to send the address on its own. */ name?: string | null; } export interface EmailSendingEmailAddressObject { /** * Email address (e.g., 'user@example.com'). */ address: string; /** * Display name for the email address (e.g., 'John Doe'). Optional; set to null or * leave it unset to send the address on its own. */ name?: string | null; } } export interface EmailSendingSendRawParams { /** * Path param: Identifier of the account. */ account_id: string; /** * Body param: Sender email address. */ from: string; /** * Body param: The full MIME-encoded email message. Should include standard RFC * 5322 headers such as From, To, Subject, and Content-Type. The from and * recipients fields in the request body control SMTP envelope routing; the From * and To headers in the MIME message control what the recipient's email client * displays. */ mime_message: string; /** * Body param: List of recipient email addresses. */ recipients: Array; } EmailSending.Subdomains = Subdomains; EmailSending.BaseSubdomains = BaseSubdomains; export declare namespace EmailSending { export { type EmailSendingSendResponse as EmailSendingSendResponse, type EmailSendingSendRawResponse as EmailSendingSendRawResponse, type EmailSendingSendParams as EmailSendingSendParams, type EmailSendingSendRawParams as EmailSendingSendRawParams, }; export { Subdomains as Subdomains, BaseSubdomains as BaseSubdomains, type SubdomainCreateResponse as SubdomainCreateResponse, type SubdomainListResponse as SubdomainListResponse, type SubdomainDeleteResponse as SubdomainDeleteResponse, type SubdomainGetResponse as SubdomainGetResponse, type SubdomainListResponsesSinglePage as SubdomainListResponsesSinglePage, type SubdomainCreateParams as SubdomainCreateParams, type SubdomainListParams as SubdomainListParams, type SubdomainDeleteParams as SubdomainDeleteParams, type SubdomainGetParams as SubdomainGetParams, }; }