# Email Sending
## Send an email
`client.EmailSending.Send(ctx, params) (*EmailSendingSendResponse, error)`
**post** `/accounts/{account_id}/email/sending/send`
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.
### 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'). Optional; set to null or leave it unset to send the address on its own.
- `Subject param.Field[string]`
Body param: Email subject line.
- `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'. Embeds the attachment 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'. Adds 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, a named address object, or an array of either.
- `UnionString`
- `type EmailSendingSendParamsBccEmailSendingEmailAddressObject struct{…}`
- `Address string`
Email address (e.g., 'user@example.com').
- `Name 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.
- `type EmailSendingSendParamsBccArray []EmailSendingSendParamsBccArrayUnion`
- `UnionString`
- `type EmailSendingSendParamsBccArrayEmailSendingEmailAddressObject struct{…}`
- `Address string`
Email address (e.g., 'user@example.com').
- `Name 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.
- `Cc param.Field[EmailSendingSendParamsCcUnion]`
Body param: CC recipient(s). A single email string, a named address object, or an array of either.
- `UnionString`
- `type EmailSendingSendParamsCcEmailSendingEmailAddressObject struct{…}`
- `Address string`
Email address (e.g., 'user@example.com').
- `Name 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.
- `type EmailSendingSendParamsCcArray []EmailSendingSendParamsCcArrayUnion`
- `UnionString`
- `type EmailSendingSendParamsCcArrayEmailSendingEmailAddressObject struct{…}`
- `Address string`
Email address (e.g., 'user@example.com').
- `Name 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.
- `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. Provide at least one of text or html (non-empty).
- `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'). Optional; set to null or leave it unset to send the address on its own.
- `Text param.Field[string]`
Body param: Plain text body of the email. Provide at least one of text or html (non-empty).
- `To param.Field[EmailSendingSendParamsToUnion]`
Body param: Recipient(s). Optional if cc or bcc is provided. A single email string, a named address object, or an array of either.
- `UnionString`
- `type EmailSendingSendParamsToEmailSendingEmailAddressObject struct{…}`
- `Address string`
Email address (e.g., 'user@example.com').
- `Name 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.
- `type EmailSendingSendParamsToArray []EmailSendingSendParamsToArrayUnion`
- `UnionString`
- `type EmailSendingSendParamsToArrayEmailSendingEmailAddressObject struct{…}`
- `Address string`
Email address (e.g., 'user@example.com').
- `Name 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.
### Returns
- `type EmailSendingSendResponse struct{…}`
- `Delivered []string`
Email addresses to which the message was delivered immediately.
- `MessageID string`
Message ID of the sent email.
- `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"),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.MessageID)
}
```
#### Response
```json
{
"errors": [
{
"code": 0,
"message": "message"
}
],
"messages": [
{
"code": 0,
"message": "message"
}
],
"result": {
"delivered": [
"recipient@example.com"
],
"message_id": "",
"permanent_bounces": [
"string"
],
"queued": [
"string"
]
},
"success": true,
"result_info": {
"count": 0,
"per_page": 0,
"total_count": 0,
"cursor": "cursor",
"page": 0
}
}
```
## Send a raw MIME email
`client.EmailSending.SendRaw(ctx, params) (*EmailSendingSendRawResponse, error)`
**post** `/accounts/{account_id}/email/sending/send_raw`
Send a raw RFC 5322 (MIME) email for the specified account. Provide the full MIME message plus the SMTP envelope (from and recipients).
### 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.
- `MessageID string`
Message ID of the sent email.
- `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.MessageID)
}
```
#### Response
```json
{
"errors": [
{
"code": 0,
"message": "message"
}
],
"messages": [
{
"code": 0,
"message": "message"
}
],
"result": {
"delivered": [
"recipient@example.com"
],
"message_id": "",
"permanent_bounces": [
"string"
],
"queued": [
"string"
]
},
"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{…}`
- `Enabled 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.
- `DKIMSelector string`
The DKIM selector used for email signing.
- `Modified Time`
The date and time the destination address was last modified.
- `PreviewEnabled bool`
Whether sent messages from this subdomain can be previewed in the activity log.
- `ReturnPathDomain string`
The return-path domain used for bounce handling.
### 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": [
{
"enabled": true,
"name": "sub.example.com",
"tag": "aabbccdd11223344aabbccdd11223344",
"created": "2014-01-02T02:20:00Z",
"dkim_selector": "cf-bounce",
"modified": "2014-01-02T02:20:00Z",
"preview_enabled": true,
"return_path_domain": "cf-bounce.sub.example.com"
}
],
"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{…}`
- `Enabled 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.
- `DKIMSelector string`
The DKIM selector used for email signing.
- `Modified Time`
The date and time the destination address was last modified.
- `PreviewEnabled bool`
Whether sent messages from this subdomain can be previewed in the activity log.
- `ReturnPathDomain string`
The return-path domain used for bounce handling.
### 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.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": {
"enabled": true,
"name": "sub.example.com",
"tag": "aabbccdd11223344aabbccdd11223344",
"created": "2014-01-02T02:20:00Z",
"dkim_selector": "cf-bounce",
"modified": "2014-01-02T02:20:00Z",
"preview_enabled": true,
"return_path_domain": "cf-bounce.sub.example.com"
}
}
```
## 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{…}`
- `Enabled 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.
- `DKIMSelector string`
The DKIM selector used for email signing.
- `Modified Time`
The date and time the destination address was last modified.
- `PreviewEnabled bool`
Whether sent messages from this subdomain can be previewed in the activity log.
- `ReturnPathDomain string`
The return-path domain used for bounce handling.
### 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.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": {
"enabled": true,
"name": "sub.example.com",
"tag": "aabbccdd11223344aabbccdd11223344",
"created": "2014-01-02T02:20:00Z",
"dkim_selector": "cf-bounce",
"modified": "2014-01-02T02:20:00Z",
"preview_enabled": true,
"return_path_domain": "cf-bounce.sub.example.com"
}
}
```
## 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
}
}
```