Skip to main content

Send

Send a batch of emails using the default context.
func (s *BatchSvcImpl) Send(params []*SendEmailRequest) (*BatchEmailResponse, error)

Parameters

params
[]*SendEmailRequest
required
Array of email requests to send in batch. Each request should follow the same structure as a single email send request.

Returns

Returns a *BatchEmailResponse containing the results of the batch send operation.

Example

emails := []*resend.SendEmailRequest{
  {
    From:    "[email protected]",
    To:      []string{"[email protected]"},
    Subject: "Welcome User 1",
    Html:    "<p>Welcome to our service!</p>",
  },
  {
    From:    "[email protected]",
    To:      []string{"[email protected]"},
    Subject: "Welcome User 2",
    Html:    "<p>Welcome to our service!</p>",
  },
}

response, err := client.Batch.Send(emails)
if err != nil {
  panic(err)
}

SendWithContext

Send a batch of emails with a custom context.
func (s *BatchSvcImpl) SendWithContext(ctx context.Context, params []*SendEmailRequest) (*BatchEmailResponse, error)

Parameters

ctx
context.Context
required
Context for the request, useful for timeouts and cancellation.
params
[]*SendEmailRequest
required
Array of email requests to send in batch.

Returns

Returns a *BatchEmailResponse containing the results of the batch send operation.

Example

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

emails := []*resend.SendEmailRequest{
  {
    From:    "[email protected]",
    To:      []string{"[email protected]"},
    Subject: "Welcome User 1",
    Html:    "<p>Welcome to our service!</p>",
  },
}

response, err := client.Batch.SendWithContext(ctx, emails)
if err != nil {
  panic(err)
}

SendWithOptions

Send a batch of emails with custom context and options.
func (s *BatchSvcImpl) SendWithOptions(ctx context.Context, params []*SendEmailRequest, options *BatchSendEmailOptions) (*BatchEmailResponse, error)

Parameters

ctx
context.Context
required
Context for the request, useful for timeouts and cancellation.
params
[]*SendEmailRequest
required
Array of email requests to send in batch.
options
*BatchSendEmailOptions
Additional options for the batch send operation.

Returns

Returns a *BatchEmailResponse containing the results of the batch send operation.

Example

options := &resend.BatchSendEmailOptions{
  IdempotencyKey:  "unique-key-123",
  BatchValidation: resend.BatchValidationPermissive,
}

emails := []*resend.SendEmailRequest{
  {
    From:    "[email protected]",
    To:      []string{"[email protected]"},
    Subject: "Welcome",
    Html:    "<p>Welcome!</p>",
  },
}

response, err := client.Batch.SendWithOptions(context.Background(), emails, options)
if err != nil {
  panic(err)
}

Types

BatchSendEmailOptions

Additional options for batch email sending.
type BatchSendEmailOptions struct {
  IdempotencyKey  string              `json:"idempotency_key,omitempty"`
  BatchValidation BatchValidationMode `json:"-"`
}
IdempotencyKey
string
Unique key to ensure idempotent requests. Prevents duplicate sends if the same key is used.
BatchValidation
BatchValidationMode
Controls the validation behavior for batch emails. Can be BatchValidationStrict (default) or BatchValidationPermissive.
  • BatchValidationStrict: Only sends the batch if all emails are valid
  • BatchValidationPermissive: Processes all emails, allowing partial success

BatchValidationMode

Validation mode constants for batch email sending.
type BatchValidationMode string

const (
  BatchValidationStrict     BatchValidationMode = "strict"
  BatchValidationPermissive BatchValidationMode = "permissive"
)
BatchValidationStrict
BatchValidationMode
Only sends the batch if all emails are valid. This is the default mode.
BatchValidationPermissive
BatchValidationMode
Processes all emails, allowing partial success. Failed emails will be listed in the Errors field of the response.

BatchEmailResponse

Response from a batch email send operation.
type BatchEmailResponse struct {
  Data   []SendEmailResponse `json:"data"`
  Errors []BatchError        `json:"errors,omitempty"`
}
Data
[]SendEmailResponse
Array of successful email send responses, each containing the email ID.
Errors
[]BatchError
Array of errors for specific emails in the batch when using permissive validation mode.

BatchError

Represents an error for a specific email in a batch request.
type BatchError struct {
  Index   int    `json:"index"`
  Message string `json:"message"`
}
Index
int
The index of the failed email in the original request array.
Message
string
Error message describing why the email failed.

Build docs developers (and LLMs) love