# Email Sending ## Send an email using the builder. `client.EmailSending.Send(ctx, params) (*EmailSendingSendResponse, error)` **post** `/accounts/{account_id}/email/sending/send` Send an email using the builder. ### Parameters - `params EmailSendingSendParams` - `AccountID param.Field[string]` Path param: Identifier of the account. - `From param.Field[EmailSendingSendParamsFromUnion]` Body param: Sender email address. Either a plain string or an object with address and name. - `UnionString` - `type EmailSendingSendParamsFromEmailSendingEmailAddressObject struct{…}` - `Address string` Email address (e.g., 'user@example.com'). - `Name string` Display name for the email address (e.g., 'John Doe'). - `Subject param.Field[string]` Body param: Email subject line. - `To param.Field[EmailSendingSendParamsToUnion]` Body param: Recipient(s). A single email string or an array of email strings. - `UnionString` - `type EmailSendingSendParamsToEmailSendingEmailAddressList []string` A list of email address strings. - `Attachments param.Field[[]EmailSendingSendParamsAttachment]` Body param: File attachments and inline images. - `type EmailSendingSendParamsAttachmentsEmailSendingEmailInlineAttachment struct{…}` - `Content string` Base64-encoded content of the attachment. - `ContentID string` Content ID used to reference this attachment in HTML via cid: URI (e.g., ). - `Disposition EmailSendingSendParamsAttachmentsEmailSendingEmailInlineAttachmentDisposition` Must be 'inline'. Indicates the attachment is embedded in the email body. - `const EmailSendingSendParamsAttachmentsEmailSendingEmailInlineAttachmentDispositionInline EmailSendingSendParamsAttachmentsEmailSendingEmailInlineAttachmentDisposition = "inline"` - `Filename string` Filename for the attachment. - `Type string` MIME type of the attachment (e.g., 'image/png', 'text/plain'). - `type EmailSendingSendParamsAttachmentsEmailSendingEmailAttachment struct{…}` - `Content string` Base64-encoded content of the attachment. - `Disposition EmailSendingSendParamsAttachmentsEmailSendingEmailAttachmentDisposition` Must be 'attachment'. Indicates a standard file attachment. - `const EmailSendingSendParamsAttachmentsEmailSendingEmailAttachmentDispositionAttachment EmailSendingSendParamsAttachmentsEmailSendingEmailAttachmentDisposition = "attachment"` - `Filename string` Filename for the attachment. - `Type string` MIME type of the attachment (e.g., 'application/pdf', 'text/plain'). - `Bcc param.Field[EmailSendingSendParamsBccUnion]` Body param: BCC recipient(s). A single email string or an array of email strings. - `UnionString` - `type EmailSendingSendParamsBccEmailSendingEmailAddressList []string` A list of email address strings. - `Cc param.Field[EmailSendingSendParamsCcUnion]` Body param: CC recipient(s). A single email string or an array of email strings. - `UnionString` - `type EmailSendingSendParamsCcEmailSendingEmailAddressList []string` A list of email address strings. - `Headers param.Field[map[string, string]]` Body param: Custom email headers as key-value pairs. - `HTML param.Field[string]` Body param: HTML body of the email. At least one of text or html must be provided. - `ReplyTo param.Field[EmailSendingSendParamsReplyToUnion]` Body param: Reply-to address. Either a plain string or an object with address and name. - `UnionString` - `type EmailSendingSendParamsReplyToEmailSendingEmailAddressObject struct{…}` - `Address string` Email address (e.g., 'user@example.com'). - `Name string` Display name for the email address (e.g., 'John Doe'). - `Text param.Field[string]` Body param: Plain text body of the email. At least one of text or html must be provided. ### Returns - `type EmailSendingSendResponse struct{…}` - `Delivered []string` Email addresses to which the message was delivered immediately. - `PermanentBounces []string` Email addresses that permanently bounced. - `Queued []string` Email addresses for which delivery was queued for later. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/email_sending" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/shared" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.EmailSending.Send(context.TODO(), email_sending.EmailSendingSendParams{ AccountID: cloudflare.F("account_id"), From: cloudflare.F[email_sending.EmailSendingSendParamsFromUnion](shared.UnionString("sender@example.com")), Subject: cloudflare.F("Monthly Report"), To: cloudflare.F[email_sending.EmailSendingSendParamsToUnion](email_sending.EmailSendingSendParamsToEmailSendingEmailAddressList([]string{"recipient@example.com"})), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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(ctx, params) (*EmailSendingSendRawResponse, error)` **post** `/accounts/{account_id}/email/sending/send_raw` Send a raw MIME email message. ### Parameters - `params EmailSendingSendRawParams` - `AccountID param.Field[string]` Path param: Identifier of the account. - `From param.Field[string]` Body param: Sender email address. - `MimeMessage param.Field[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 param.Field[[]string]` Body param: List of recipient email addresses. ### Returns - `type EmailSendingSendRawResponse struct{…}` - `Delivered []string` Email addresses to which the message was delivered immediately. - `PermanentBounces []string` Email addresses that permanently bounced. - `Queued []string` Email addresses for which delivery was queued for later. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/email_sending" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.EmailSending.SendRaw(context.TODO(), email_sending.EmailSendingSendRawParams{ AccountID: cloudflare.F("account_id"), From: cloudflare.F("sender@example.com"), MimeMessage: cloudflare.F("From: sender@example.com\r\nTo: recipient@example.com\r\nSubject: Hello\r\nContent-Type: text/plain\r\n\r\nHello, World!"), Recipients: cloudflare.F([]string{"recipient@example.com"}), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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 } } ``` # Subdomains ## List sending subdomains `client.EmailSending.Subdomains.List(ctx, query) (*SinglePage[SubdomainListResponse], error)` **get** `/zones/{zone_id}/email/sending/subdomains` Lists all sending-enabled subdomains for the zone. ### Parameters - `query SubdomainListParams` - `ZoneID param.Field[string]` Identifier. ### Returns - `type SubdomainListResponse struct{…}` - `EmailSendingEnabled bool` Whether Email Sending is enabled on this subdomain. - `Name string` The subdomain domain name. - `Tag string` Sending subdomain identifier. - `Created Time` The date and time the destination address has been created. - `EmailSendingDKIMSelector string` The DKIM selector used for email signing. - `EmailSendingReturnPathDomain string` The return-path domain used for bounce handling. - `Enabled bool` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `Modified Time` The date and time the destination address was last modified. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/email_sending" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) page, err := client.EmailSending.Subdomains.List(context.TODO(), email_sending.SubdomainListParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### 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(ctx, subdomainID, query) (*SubdomainGetResponse, error)` **get** `/zones/{zone_id}/email/sending/subdomains/{subdomain_id}` Gets information for a specific sending subdomain. ### Parameters - `subdomainID string` Sending subdomain identifier. - `query SubdomainGetParams` - `ZoneID param.Field[string]` Identifier. ### Returns - `type SubdomainGetResponse struct{…}` - `EmailSendingEnabled bool` Whether Email Sending is enabled on this subdomain. - `Name string` The subdomain domain name. - `Tag string` Sending subdomain identifier. - `Created Time` The date and time the destination address has been created. - `EmailSendingDKIMSelector string` The DKIM selector used for email signing. - `EmailSendingReturnPathDomain string` The return-path domain used for bounce handling. - `Enabled bool` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `Modified Time` The date and time the destination address was last modified. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/email_sending" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) subdomain, err := client.EmailSending.Subdomains.Get( context.TODO(), "aabbccdd11223344aabbccdd11223344", email_sending.SubdomainGetParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", subdomain.EmailSendingEnabled) } ``` #### 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.New(ctx, params) (*SubdomainNewResponse, error)` **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 SubdomainNewParams` - `ZoneID param.Field[string]` Path param: Identifier. - `Name param.Field[string]` Body param: The subdomain name. Must be within the zone. ### Returns - `type SubdomainNewResponse struct{…}` - `EmailSendingEnabled bool` Whether Email Sending is enabled on this subdomain. - `Name string` The subdomain domain name. - `Tag string` Sending subdomain identifier. - `Created Time` The date and time the destination address has been created. - `EmailSendingDKIMSelector string` The DKIM selector used for email signing. - `EmailSendingReturnPathDomain string` The return-path domain used for bounce handling. - `Enabled bool` Whether Email Routing (receiving) is enabled on this subdomain. Read-only; included for informational purposes since both services share the subdomain row. - `Modified Time` The date and time the destination address was last modified. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/email_sending" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) subdomain, err := client.EmailSending.Subdomains.New(context.TODO(), email_sending.SubdomainNewParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Name: cloudflare.F("sub.example.com"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", subdomain.EmailSendingEnabled) } ``` #### 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(ctx, subdomainID, body) (*SubdomainDeleteResponse, error)` **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. - `body SubdomainDeleteParams` - `ZoneID param.Field[string]` Identifier. ### Returns - `type SubdomainDeleteResponse struct{…}` - `Errors []SubdomainDeleteResponseError` - `Code int64` - `Message string` - `DocumentationURL string` - `Source SubdomainDeleteResponseErrorsSource` - `Pointer string` - `Messages []SubdomainDeleteResponseMessage` - `Code int64` - `Message string` - `DocumentationURL string` - `Source SubdomainDeleteResponseMessagesSource` - `Pointer string` - `Success SubdomainDeleteResponseSuccess` Whether the API call was successful. - `const SubdomainDeleteResponseSuccessTrue SubdomainDeleteResponseSuccess = true` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/email_sending" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) subdomain, err := client.EmailSending.Subdomains.Delete( context.TODO(), "aabbccdd11223344aabbccdd11223344", email_sending.SubdomainDeleteParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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 } ``` # DNS ## Get sending subdomain DNS records `client.EmailSending.Subdomains.DNS.Get(ctx, subdomainID, query) (*SinglePage[DNSRecord], error)` **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. - `query SubdomainDNSGetParams` - `ZoneID param.Field[string]` Identifier. ### Returns - `type DNSRecord struct{…}` 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 float64` Required for MX, SRV and URI records. Unused by other record types. Records with lower priorities are preferred. - `TTL DNSRecordTTL` Time to live, in seconds, of the DNS record. Must be between 60 and 86400, or 1 for 'automatic'. - `float64` - `type DNSRecordTTL float64` Time to live, in seconds, of the DNS record. Must be between 60 and 86400, or 1 for 'automatic'. - `const DNSRecordTTL1 DNSRecordTTL = 1` - `Type DNSRecordType` DNS record type. - `const DNSRecordTypeA DNSRecordType = "A"` - `const DNSRecordTypeAAAA DNSRecordType = "AAAA"` - `const DNSRecordTypeCNAME DNSRecordType = "CNAME"` - `const DNSRecordTypeHTTPS DNSRecordType = "HTTPS"` - `const DNSRecordTypeTXT DNSRecordType = "TXT"` - `const DNSRecordTypeSRV DNSRecordType = "SRV"` - `const DNSRecordTypeLOC DNSRecordType = "LOC"` - `const DNSRecordTypeMX DNSRecordType = "MX"` - `const DNSRecordTypeNS DNSRecordType = "NS"` - `const DNSRecordTypeCERT DNSRecordType = "CERT"` - `const DNSRecordTypeDNSKEY DNSRecordType = "DNSKEY"` - `const DNSRecordTypeDS DNSRecordType = "DS"` - `const DNSRecordTypeNAPTR DNSRecordType = "NAPTR"` - `const DNSRecordTypeSMIMEA DNSRecordType = "SMIMEA"` - `const DNSRecordTypeSSHFP DNSRecordType = "SSHFP"` - `const DNSRecordTypeSVCB DNSRecordType = "SVCB"` - `const DNSRecordTypeTLSA DNSRecordType = "TLSA"` - `const DNSRecordTypeURI DNSRecordType = "URI"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/email_sending" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) page, err := client.EmailSending.Subdomains.DNS.Get( context.TODO(), "aabbccdd11223344aabbccdd11223344", email_sending.SubdomainDNSGetParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### 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 } } ```