Creates a new broadcast based on the provided parameters. By default, broadcasts are created as drafts. You can optionally send them immediately or schedule them for later.
Methods
Create
Create(params *CreateBroadcastRequest) (CreateBroadcastResponse, error)
Creates a broadcast using the default background context.
CreateWithContext
CreateWithContext(ctx context.Context, params *CreateBroadcastRequest) (CreateBroadcastResponse, error)
Creates a broadcast with a custom context for cancellation and timeout control.
Request
The ID of the segment to send the broadcast to.
The sender email address.
A name to identify the broadcast.
The HTML content of the email.
The plain text content of the email.
An array of email addresses to set as reply-to addresses.
Set to true to send the broadcast immediately upon creation instead of creating a draft.
Schedule the email to be sent later. Accepts natural language (e.g., “in 1 min”) or ISO 8601 format (e.g., “2024-08-05T11:52:01.858Z”). Only valid when send is true.
Deprecated. Use segment_id instead.
Response
The unique identifier for the created broadcast.
Example
package main
import (
"fmt"
"github.com/resend/resend-go/v2"
)
func main() {
client := resend.NewClient("re_123456789")
params := &resend.CreateBroadcastRequest{
Name: "Product Launch",
SegmentId: "seg_123456",
From: "[email protected]",
Subject: "New Product Launch",
Html: "<h1>Check out our new product!</h1>",
ReplyTo: []string{"[email protected]"},
}
broadcast, err := client.Broadcasts.Create(params)
if err != nil {
panic(err)
}
fmt.Println("Broadcast ID:", broadcast.Id)
}
params := &resend.CreateBroadcastRequest{
Name: "Newsletter",
SegmentId: "seg_123456",
From: "[email protected]",
Subject: "Weekly Newsletter",
Html: "<h1>This week's updates</h1>",
Send: true,
}
broadcast, err := client.Broadcasts.Create(params)
Example: Create and schedule
params := &resend.CreateBroadcastRequest{
Name: "Scheduled Newsletter",
SegmentId: "seg_123456",
From: "[email protected]",
Subject: "Weekly Newsletter",
Html: "<h1>This week's updates</h1>",
Send: true,
ScheduledAt: "2024-12-01T19:32:22.980Z",
}
broadcast, err := client.Broadcasts.Create(params)
At least one of html or text must be provided. Both segment_id (or deprecated audience_id) and from are required fields.