Skip to content
Start here

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.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
ParametersExpand Collapse
params EmailSendingSendParams
AccountID param.Field[string]

Path param: Identifier of the account.

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.

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]optional

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.

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.

Filename string

Filename for the attachment.

Type string

MIME type of the attachment (e.g., 'application/pdf', 'text/plain').

Bcc param.Field[EmailSendingSendParamsBccUnion]optional

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]optional

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]]optional

Body param: Custom email headers as key-value pairs.

HTML param.Field[string]optional

Body param: HTML body of the email. At least one of text or html must be provided.

ReplyTo param.Field[EmailSendingSendParamsReplyToUnion]optional

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]optional

Body param: Plain text body of the email. At least one of text or html must be provided.

ReturnsExpand Collapse
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.

Send an email using the builder.

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)
}
{
  "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
  }
}
Returns Examples
{
  "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
  }
}