# Email Sending ## Send an email using the builder. `client.emailSending.send(EmailSendingSendParamsparams, RequestOptionsoptions?): EmailSendingSendResponse` **post** `/accounts/{account_id}/email/sending/send` Send an email using the builder. ### Parameters - `params: EmailSendingSendParams` - `account_id: string` Path param: Identifier of the account. - `from: string | EmailSendingEmailAddressObject` Body param: Sender email address. Either a plain string or an object with address and name. - `string` - `EmailSendingEmailAddressObject` - `address: string` Email address (e.g., 'user@example.com'). - `name: string` Display name for the email address (e.g., 'John Doe'). - `subject: string` Body param: Email subject line. - `to: string | Array` Body param: Recipient(s). A single email string or an array of email strings. - `string` - `Array` - `attachments?: Array` Body param: File attachments and inline images. - `EmailSendingEmailInlineAttachment` - `content: string` Base64-encoded content of the attachment. - `content_id: string` Content ID used to reference this attachment in HTML via cid: URI (e.g., ). - `disposition: "inline"` Must be 'inline'. Indicates the attachment is embedded in the email body. - `"inline"` - `filename: string` Filename for the attachment. - `type: string` MIME type of the attachment (e.g., 'image/png', 'text/plain'). - `EmailSendingEmailAttachment` - `content: string` Base64-encoded content of the attachment. - `disposition: "attachment"` Must be 'attachment'. Indicates a standard file attachment. - `"attachment"` - `filename: string` Filename for the attachment. - `type: string` MIME type of the attachment (e.g., 'application/pdf', 'text/plain'). - `bcc?: string | Array` Body param: BCC recipient(s). A single email string or an array of email strings. - `string` - `Array` - `cc?: string | Array` Body param: CC recipient(s). A single email string or an array of email strings. - `string` - `Array` - `headers?: Record` Body param: Custom email headers as key-value pairs. - `html?: string` Body param: HTML body of the email. At least one of text or html must be provided. - `reply_to?: string | EmailSendingEmailAddressObject` Body param: Reply-to address. Either a plain string or an object with address and name. - `string` - `EmailSendingEmailAddressObject` - `address: string` Email address (e.g., 'user@example.com'). - `name: string` Display name for the email address (e.g., 'John Doe'). - `text?: string` Body param: Plain text body of the email. At least one of text or html must be provided. ### Returns - `EmailSendingSendResponse` - `delivered: Array` Email addresses to which the message was delivered immediately. - `permanent_bounces: Array` Email addresses that permanently bounced. - `queued: Array` Email addresses for which delivery was queued for later. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.emailSending.send({ account_id: 'account_id', from: 'sender@example.com', subject: 'Monthly Report', to: ['recipient@example.com'], }); console.log(response.delivered); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "delivered": [ "recipient@example.com" ], "permanent_bounces": [ "dev@stainless.com" ], "queued": [ "dev@stainless.com" ] }, "success": true, "result_info": { "count": 0, "per_page": 0, "total_count": 0, "cursor": "cursor", "page": 0 } } ``` ## Send a raw MIME email message. `client.emailSending.sendRaw(EmailSendingSendRawParamsparams, RequestOptionsoptions?): EmailSendingSendRawResponse` **post** `/accounts/{account_id}/email/sending/send_raw` Send a raw MIME email message. ### Parameters - `params: EmailSendingSendRawParams` - `account_id: string` Path param: Identifier of the account. - `from: string` Body param: Sender email address. - `mime_message: 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. - `recipients: Array` Body param: List of recipient email addresses. ### Returns - `EmailSendingSendRawResponse` - `delivered: Array` Email addresses to which the message was delivered immediately. - `permanent_bounces: Array` Email addresses that permanently bounced. - `queued: Array` Email addresses for which delivery was queued for later. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); 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'], }); console.log(response.delivered); ``` #### Response ```json { "errors": [ { "code": 0, "message": "message" } ], "messages": [ { "code": 0, "message": "message" } ], "result": { "delivered": [ "recipient@example.com" ], "permanent_bounces": [ "dev@stainless.com" ], "queued": [ "dev@stainless.com" ] }, "success": true, "result_info": { "count": 0, "per_page": 0, "total_count": 0, "cursor": "cursor", "page": 0 } } ``` ## Domain Types ### Email Sending Send Response - `EmailSendingSendResponse` - `delivered: Array` Email addresses to which the message was delivered immediately. - `permanent_bounces: Array` Email addresses that permanently bounced. - `queued: Array` Email addresses for which delivery was queued for later. ### Email Sending Send Raw Response - `EmailSendingSendRawResponse` - `delivered: Array` Email addresses to which the message was delivered immediately. - `permanent_bounces: Array` Email addresses that permanently bounced. - `queued: Array` Email addresses for which delivery was queued for later. # Subdomains ## List sending subdomains `client.emailSending.subdomains.list(SubdomainListParamsparams, RequestOptionsoptions?): SinglePage` **get** `/zones/{zone_id}/email/sending/subdomains` Lists all sending-enabled subdomains for the zone. ### Parameters - `params: SubdomainListParams` - `zone_id: string` Identifier. ### Returns - `SubdomainListResponse` - `email_sending_enabled: boolean` Whether Email Sending is enabled on this subdomain. - `name: string` The subdomain domain name. - `tag: string` Sending subdomain identifier. - `created?: string` The date and time the destination address has been created. - `email_sending_dkim_selector?: string` The DKIM selector used for email signing. - `email_sending_return_path_domain?: string` The return-path domain used for bounce handling. - `enabled?: boolean` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `modified?: string` The date and time the destination address was last modified. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const subdomainListResponse of client.emailSending.subdomains.list({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(subdomainListResponse.email_sending_enabled); } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "email_sending_enabled": true, "name": "sub.example.com", "tag": "aabbccdd11223344aabbccdd11223344", "created": "2014-01-02T02:20:00Z", "email_sending_dkim_selector": "cf-bounce", "email_sending_return_path_domain": "cf-bounce.sub.example.com", "enabled": true, "modified": "2014-01-02T02:20:00Z" } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000, "total_pages": 100 } } ``` ## Get a sending subdomain `client.emailSending.subdomains.get(stringsubdomainId, SubdomainGetParamsparams, RequestOptionsoptions?): SubdomainGetResponse` **get** `/zones/{zone_id}/email/sending/subdomains/{subdomain_id}` Gets information for a specific sending subdomain. ### Parameters - `subdomainId: string` Sending subdomain identifier. - `params: SubdomainGetParams` - `zone_id: string` Identifier. ### Returns - `SubdomainGetResponse` - `email_sending_enabled: boolean` Whether Email Sending is enabled on this subdomain. - `name: string` The subdomain domain name. - `tag: string` Sending subdomain identifier. - `created?: string` The date and time the destination address has been created. - `email_sending_dkim_selector?: string` The DKIM selector used for email signing. - `email_sending_return_path_domain?: string` The return-path domain used for bounce handling. - `enabled?: boolean` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `modified?: string` The date and time the destination address was last modified. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const subdomain = await client.emailSending.subdomains.get('aabbccdd11223344aabbccdd11223344', { zone_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(subdomain.email_sending_enabled); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "email_sending_enabled": true, "name": "sub.example.com", "tag": "aabbccdd11223344aabbccdd11223344", "created": "2014-01-02T02:20:00Z", "email_sending_dkim_selector": "cf-bounce", "email_sending_return_path_domain": "cf-bounce.sub.example.com", "enabled": true, "modified": "2014-01-02T02:20:00Z" } } ``` ## Create a sending subdomain `client.emailSending.subdomains.create(SubdomainCreateParamsparams, RequestOptionsoptions?): SubdomainCreateResponse` **post** `/zones/{zone_id}/email/sending/subdomains` Creates a new sending subdomain or re-enables sending on an existing subdomain that had it disabled. If zone-level Email Sending has not been enabled yet, the zone flag is automatically set when the entitlement is present. ### Parameters - `params: SubdomainCreateParams` - `zone_id: string` Path param: Identifier. - `name: string` Body param: The subdomain name. Must be within the zone. ### Returns - `SubdomainCreateResponse` - `email_sending_enabled: boolean` Whether Email Sending is enabled on this subdomain. - `name: string` The subdomain domain name. - `tag: string` Sending subdomain identifier. - `created?: string` The date and time the destination address has been created. - `email_sending_dkim_selector?: string` The DKIM selector used for email signing. - `email_sending_return_path_domain?: string` The return-path domain used for bounce handling. - `enabled?: boolean` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `modified?: string` The date and time the destination address was last modified. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const subdomain = await client.emailSending.subdomains.create({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353', name: 'sub.example.com', }); console.log(subdomain.email_sending_enabled); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "email_sending_enabled": true, "name": "sub.example.com", "tag": "aabbccdd11223344aabbccdd11223344", "created": "2014-01-02T02:20:00Z", "email_sending_dkim_selector": "cf-bounce", "email_sending_return_path_domain": "cf-bounce.sub.example.com", "enabled": true, "modified": "2014-01-02T02:20:00Z" } } ``` ## Delete a sending subdomain `client.emailSending.subdomains.delete(stringsubdomainId, SubdomainDeleteParamsparams, RequestOptionsoptions?): SubdomainDeleteResponse` **delete** `/zones/{zone_id}/email/sending/subdomains/{subdomain_id}` Disables sending on a subdomain and removes its DNS records. If routing is still active on the subdomain, only sending is disabled. ### Parameters - `subdomainId: string` Sending subdomain identifier. - `params: SubdomainDeleteParams` - `zone_id: string` Identifier. ### Returns - `SubdomainDeleteResponse` - `errors: Array` - `code: number` - `message: string` - `documentation_url?: string` - `source?: Source` - `pointer?: string` - `messages: Array` - `code: number` - `message: string` - `documentation_url?: string` - `source?: Source` - `pointer?: string` - `success: true` Whether the API call was successful. - `true` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const subdomain = await client.emailSending.subdomains.delete('aabbccdd11223344aabbccdd11223344', { zone_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(subdomain.errors); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true } ``` ## Domain Types ### Subdomain List Response - `SubdomainListResponse` - `email_sending_enabled: boolean` Whether Email Sending is enabled on this subdomain. - `name: string` The subdomain domain name. - `tag: string` Sending subdomain identifier. - `created?: string` The date and time the destination address has been created. - `email_sending_dkim_selector?: string` The DKIM selector used for email signing. - `email_sending_return_path_domain?: string` The return-path domain used for bounce handling. - `enabled?: boolean` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `modified?: string` The date and time the destination address was last modified. ### Subdomain Get Response - `SubdomainGetResponse` - `email_sending_enabled: boolean` Whether Email Sending is enabled on this subdomain. - `name: string` The subdomain domain name. - `tag: string` Sending subdomain identifier. - `created?: string` The date and time the destination address has been created. - `email_sending_dkim_selector?: string` The DKIM selector used for email signing. - `email_sending_return_path_domain?: string` The return-path domain used for bounce handling. - `enabled?: boolean` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `modified?: string` The date and time the destination address was last modified. ### Subdomain Create Response - `SubdomainCreateResponse` - `email_sending_enabled: boolean` Whether Email Sending is enabled on this subdomain. - `name: string` The subdomain domain name. - `tag: string` Sending subdomain identifier. - `created?: string` The date and time the destination address has been created. - `email_sending_dkim_selector?: string` The DKIM selector used for email signing. - `email_sending_return_path_domain?: string` The return-path domain used for bounce handling. - `enabled?: boolean` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `modified?: string` The date and time the destination address was last modified. ### Subdomain Delete Response - `SubdomainDeleteResponse` - `errors: Array` - `code: number` - `message: string` - `documentation_url?: string` - `source?: Source` - `pointer?: string` - `messages: Array` - `code: number` - `message: string` - `documentation_url?: string` - `source?: Source` - `pointer?: string` - `success: true` Whether the API call was successful. - `true` # DNS ## Get sending subdomain DNS records `client.emailSending.subdomains.dns.get(stringsubdomainId, DNSGetParamsparams, RequestOptionsoptions?): SinglePage` **get** `/zones/{zone_id}/email/sending/subdomains/{subdomain_id}/dns` Returns the expected DNS records for a sending subdomain. ### Parameters - `subdomainId: string` Sending subdomain identifier. - `params: DNSGetParams` - `zone_id: string` Identifier. ### Returns - `DNSRecord` List of records needed to enable an Email Routing zone. - `content?: string` DNS record content. - `name?: string` DNS record name (or @ for the zone apex). - `priority?: number` Required for MX, SRV and URI records. Unused by other record types. Records with lower priorities are preferred. - `ttl?: number | 1` Time to live, in seconds, of the DNS record. Must be between 60 and 86400, or 1 for 'automatic'. - `number` - `1` - `1` - `type?: "A" | "AAAA" | "CNAME" | 15 more` DNS record type. - `"A"` - `"AAAA"` - `"CNAME"` - `"HTTPS"` - `"TXT"` - `"SRV"` - `"LOC"` - `"MX"` - `"NS"` - `"CERT"` - `"DNSKEY"` - `"DS"` - `"NAPTR"` - `"SMIMEA"` - `"SSHFP"` - `"SVCB"` - `"TLSA"` - `"URI"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const dnsRecord of client.emailSending.subdomains.dns.get( 'aabbccdd11223344aabbccdd11223344', { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, )) { console.log(dnsRecord.content); } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "content": "route1.mx.cloudflare.net", "name": "example.com", "priority": 12, "ttl": 1, "type": "NS" } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000, "total_pages": 100 } } ```