Hello {{{FIRST_NAME|there}}}!
", "text": "Hello {{{FIRST_NAME|there}}}!", "status": "draft", "created_at": "2024-12-01T19:32:22.980Z", "scheduled_at": null, "sent_at": null, "topic_id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e" } ```it works!
', }, ]); ``` ```php PHP theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->batch->send([ [ 'from' => 'Acmeit works!
', ] ]); ``` ```py Python theme={null} import resend from typing import List resend.api_key = "re_xxxxxxxxx" params: List[resend.Emails.SendParams] = [ { "from": "Acmeit works!
", } ] resend.Batch.send(params) ``` ```rb Ruby theme={null} require "resend" Resend.api_key = 're_xxxxxxxxx' params = [ { "from": "Acmeit works!
", } ] Resend::Batch.send(params) ``` ```go Go theme={null} package examples import ( "fmt" "os" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") var batchEmails = []*resend.SendEmailRequest{ { From: "Acmeit works!
", }, } sent, err := client.Batch.SendWithContext(ctx, batchEmails) if err != nil { panic(err) } fmt.Println(sent.Data) } ``` ```rust Rust theme={null} use resend_rs::types::CreateEmailBaseOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let emails = vec![ CreateEmailBaseOptions::new( "Acmeit works!
"), ]; let _emails = resend.batch.send(emails).await?; Ok(()) } ``` ```java Java theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateEmailOptions firstEmail = CreateEmailOptions.builder() .from("Acmeit works!
") .build(); CreateBatchEmailsResponse data = resend.batch().send( Arrays.asList(firstEmail, secondEmail) ); } } ``` ```csharp .NET theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var mail1 = new EmailMessage() { From = "Acmeit works!
", }; var mail2 = new EmailMessage() { From = "Acmeit works!
", }; var resp = await resend.EmailBatchAsync( [ mail1, mail2 ] ); Console.WriteLine( "Nr Emails={0}", resp.Content.Count ); ``` ```bash cURL theme={null} curl -X POST 'https://api.resend.com/emails/batch' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d $'[ { "from": "Acmeit works!
" } ]' ```it works!
', replyTo: 'onboarding@resend.dev', }); ``` ```php PHP theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->emails->send([ 'from' => 'Acmeit works!
', 'reply_to': 'onboarding@resend.dev' ]); ``` ```python Python theme={null} import resend resend.api_key = "re_xxxxxxxxx" params: resend.Emails.SendParams = { "from": "Acmeit works!
", "reply_to": "onboarding@resend.dev" } email = resend.Emails.send(params) print(email) ``` ```rb Ruby theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" params = { "from": "Acmeit works!
", "reply_to": "onboarding@resend.dev" } sent = Resend::Emails.send(params) puts sent ``` ```go Go theme={null} import ( "fmt" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") params := &resend.SendEmailRequest{ From: "Acmeit works!
", ReplyTo: "onboarding@resend.dev" } sent, err := client.Emails.SendWithContext(ctx, params) if err != nil { panic(err) } fmt.Println(sent.Id) } ``` ```rust Rust theme={null} use resend_rs::types::{CreateEmailBaseOptions}; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "Acmeit works!
"; let reply_to = "onboarding@resend.dev"; let email = CreateEmailBaseOptions::new(from, to, subject) .with_html(html); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateEmailOptions params = CreateEmailOptions.builder() .from("Acmeit works!
") .replyTo("onboarding@resend.dev") .build(); CreateEmailResponse data = resend.emails().send(params); } } ``` ```csharp .NET theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var resp = await resend.EmailSendAsync( new EmailMessage() { From = "Acmeit works!
", ReplyTo = "onboarding@resend.dev", } ); Console.WriteLine( "Email Id={0}", resp.Content ); ``` ```bash cURL theme={null} curl -X POST 'https://api.resend.com/emails' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d $'{ "from": "Acmeit works!
", "reply_to": "onboarding@resend.dev" }' ```Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
', variables: [ { key: 'PRODUCT', type: 'string', fallbackValue: 'item', }, { key: 'PRICE', type: 'number', fallbackValue: 25, } ], }); // Or create and publish a template in one step await resend.templates.create({ ... }).publish(); ``` ```php PHP theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->templates->create([ 'name' => 'order-confirmation', 'html' => 'Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
', 'variables' => [ [ 'key' => 'PRODUCT', 'type' => 'string', 'fallback_value' => 'item', ], [ 'key' => 'PRICE', 'type' => 'number', 'fallback_value' => 25, ] ], ]); ``` ```py Python theme={null} import resend resend.api_key = "re_xxxxxxxxx" resend.Templates.create({ "name": "order-confirmation", "html": "Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
", "variables": [ { "key": "PRODUCT", "type": "string", "fallback_value": "item", }, { "key": "PRICE", "type": "number", "fallback_value": 25, } ], }) ``` ```ruby Ruby theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" Resend::Templates.create( name: "order-confirmation", html: "Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
", variables: [ { key: "PRODUCT", type: "string", fallback_value: "item" }, { key: "PRICE", type: "number", fallback_value: 25 } ] ) ``` ```go Go theme={null} import ( "context" "github.com/resend/resend-go/v3" ) func main() { client := resend.NewClient("re_xxxxxxxxx") template, err := client.Templates.CreateWithContext(context.TODO(), &resend.CreateTemplateRequest{ Name: "order-confirmation", Html: "Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
", Variables: []*resend.TemplateVariable{ { Key: "PRODUCT", Type: resend.VariableTypeString, FallbackValue: "item", }, { Key: "PRICE", Type: resend.VariableTypeNumber, FallbackValue: 25, } }, }) } ``` ```rust Rust theme={null} use resend_rs::{ types::{CreateTemplateOptions, Variable, VariableType}, Resend, Result, }; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let name = "order-confirmation"; let html = "Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
"; let variables = [ Variable::new("PRODUCT", VariableType::String).with_fallback("item"), Variable::new("PRICE", VariableType::Number).with_fallback(25) ]; let opts = CreateTemplateOptions::new(name, html).with_variables(&variables); let template = resend.templates.create(opts).await?; let _published = resend.templates.publish(&template.id).await?; Ok(()) } ``` ```java Java theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateTemplateOptions params = CreateTemplateOptions.builder() .name("order-confirmation") .html("Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
") .addVariable(new Variable("PRODUCT", VariableType.STRING, "item")) .addVariable(new Variable("PRICE", VariableType.NUMBER, 25)) .build(); CreateTemplateResponseSuccess data = resend.templates().create(params); } } ``` ```csharp .NET theme={null} using Resend; IResend resend = ResendClient.Create("re_xxxxxxxxx"); var variables = new ListName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", "variables": [ { "key": "PRODUCT", "type": "string", "fallback_value": "item" }, { "key": "PRICE", "type": "number", "fallback_value": 25 } ] }' ```Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
', }, ); ``` ```php PHP theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->templates->update('34a080c9-b17d-4187-ad80-5af20266e535', [ 'name' => 'order-confirmation', 'html' => 'Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
', ]); ``` ```py Python theme={null} import resend resend.api_key = "re_xxxxxxxxx" resend.Templates.update({ "id": "34a080c9-b17d-4187-ad80-5af20266e535", "name": "order-confirmation", "html": "Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
", }) ``` ```ruby Ruby theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" Resend::Templates.update("34a080c9-b17d-4187-ad80-5af20266e535", { name: "order-confirmation", html: "Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
" }) ``` ```go Go theme={null} import ( "context" "github.com/resend/resend-go/v3" ) func main() { client := resend.NewClient("re_xxxxxxxxx") template, err := client.Templates.UpdateWithContext(context.TODO(), "34a080c9-b17d-4187-ad80-5af20266e535", &resend.UpdateTemplateRequest{ Name: "order-confirmation", Html: "Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
", }) } ``` ```rust Rust theme={null} use resend_rs::{ types::UpdateTemplateOptions, Resend, Result, }; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let name = "order-confirmation"; let html = "Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
"; let update = UpdateTemplateOptions::new(name, html); let _template = resend .templates .update("34a080c9-b17d-4187-ad80-5af20266e535", update) .await?; Ok(()) } ``` ```java Java theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); UpdateTemplateOptions params = UpdateTemplateOptions.builder() .name("order-confirmation") .html("Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
") .build(); UpdateTemplateResponseSuccess data = resend.templates().update("34a080c9-b17d-4187-ad80-5af20266e535", params); } } ``` ```csharp .NET theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI await resend.TemplateUpdateAsync( templateId: new Guid( "e169aa45-1ecf-4183-9955-b1499d5701d3" ), new TemplateData() { HtmlBody = "Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
", } ); ``` ```bash cURL theme={null} curl -X PATCH 'https://api.resend.com/templates/34a080c9-b17d-4187-ad80-5af20266e535' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d $'{ "name": "order-confirmation", "html": "Total: {{{PRICE}}}
Name: {{{PRODUCT}}}
" }' ```Thanks for the payment
', attachments: [ { path: 'https://resend.com/static/sample/invoice.pdf', filename: 'invoice.pdf', }, ], }); ``` ```php PHP {10-11} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->emails->send([ 'from' => 'AcmeThanks for the payment
', 'attachments' => [ [ 'path' => 'https://resend.com/static/sample/invoice.pdf', 'filename' => 'invoice.pdf' ] ] ]); ``` ```python Python {6-7} theme={null} import resend resend.api_key = "re_xxxxxxxxx" attachment: resend.RemoteAttachment = { "path": "https://resend.com/static/sample/invoice.pdf", "filename": "invoice.pdf", } params: resend.Emails.SendParams = { "from": "AcmeThanks for the payment
", "attachments": [attachment], } resend.Emails.send(params) ``` ```rb Ruby {12-13} theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" params = { "from": "AcmeThanks for the payment
", "attachments": [ { "path": "https://resend.com/static/sample/invoice.pdf", "filename": 'invoice.pdf', } ] } Resend::Emails.send(params) ``` ```go Go {12-13} theme={null} import ( "fmt" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") attachment := &resend.Attachment{ Path: "https://resend.com/static/sample/invoice.pdf", Filename: "invoice.pdf", } params := &resend.SendEmailRequest{ From: "AcmeThanks for the payment
", Attachments: []*resend.Attachment{attachment}, } sent, err := client.Emails.SendWithContext(ctx, params) if err != nil { panic(err) } fmt.Println(sent.Id) } ``` ```rust Rust {12-13} theme={null} use resend_rs::types::{CreateAttachment, CreateEmailBaseOptions}; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "AcmeThanks for the payment
") .with_attachment(CreateAttachment::from_path(path).with_filename(filename)); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java {8-9} theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); Attachment att = Attachment.builder() .path("https://resend.com/static/sample/invoice.pdf") .fileName("invoice.pdf") .build(); CreateEmailOptions params = CreateEmailOptions.builder() .from("AcmeThanks for the payment
") .attachments(att) .build(); CreateEmailResponse data = resend.emails().send(params); } } ``` ```csharp .NET {14-18} theme={null} using Resend; using System.Collections.Generic; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var message = new EmailMessage() { From = "AcmeThanks for the payment
", }; message.Attachments = new ListThanks for the payment
", "attachments": [ { "path": "https://resend.com/static/sample/invoice.pdf", "filename": "invoice.pdf" } ] }' ```Thanks for the payment
', attachments: [ { content: attachment, filename: 'invoice.pdf', }, ], }); ``` ```php PHP {10-11} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->emails->send([ 'from' => 'AcmeThanks for the payment
', 'attachments' => [ [ 'filename' => 'invoice.pdf', 'content' => $invoiceBuffer ] ] ]); ``` ```python Python {10} theme={null} import os import resend resend.api_key = "re_xxxxxxxxx" f: bytes = open( os.path.join(os.path.dirname(__file__), "../static/invoice.pdf"), "rb" ).read() attachment: resend.Attachment = {"content": list(f), "filename": "invoice.pdf"} params: resend.Emails.SendParams = { "from": "AcmeThanks for the payment
", "attachments": [attachment], } resend.Emails.send(params) ``` ```rb Ruby {14-15} theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" file = IO.read("invoice.pdf") params = { "from": "AcmeThanks for the payment
", "attachments": [ { "content": file.bytes, "filename": 'invoice.pdf', } ] } Resend::Emails.send(params) ``` ```go Go {19-20} theme={null} import ( "fmt" "os" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") pwd, _ := os.Getwd() f, err := os.ReadFile(pwd + "/static/invoice.pdf") if err != nil { panic(err) } attachment := &resend.Attachment{ Content: f, Filename: "invoice.pdf", } params := &resend.SendEmailRequest{ From: "AcmeThanks for the payment
", Attachments: []*resend.Attachment{attachment}, } sent, err := client.Emails.SendWithContext(ctx, params) if err != nil { panic(err) } fmt.Println(sent.Id) } ``` ```rust Rust {22} theme={null} use std::fs::File; use std::io::Read; use resend_rs::types::{CreateAttachment, CreateEmailBaseOptions}; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "AcmeThanks for the payment
") .with_attachment(CreateAttachment::from_content(invoice).with_filename(filename)); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java {8-9} theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); Attachment att = Attachment.builder() .fileName("invoice.pdf") .content("invoiceBuffer") .build(); CreateEmailOptions params = CreateEmailOptions.builder() .from("AcmeThanks for the payment
") .attachments(att) .build(); CreateEmailOptions params = CreateEmailOptions.builder() } } ``` ```csharp .NET {15-19} theme={null} using Resend; using System.Collections.Generic; using System.IO; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var message = new EmailMessage() { From = "AcmeThanks for the payment
", }; message.Attachments = new ListThanks for the payment
", "attachments": [ { "content": "UmVzZW5kIGF0dGFjaG1lbnQgZXhhbXBsZS4gTmljZSBqb2Igc2VuZGluZyB0aGUgZW1haWwh%", "filename": "invoice.txt" } ] }' ```Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Thanks for signing up!
', }, { from: 'AcmeYour order has been confirmed.
', }, ]); console.log(data); ``` ```php PHP theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->batch->send([ [ 'from' => 'AcmeThanks for signing up!
', ], [ 'from' => 'AcmeYour order has been confirmed.
', ] ]); ``` ```py Python theme={null} import resend from typing import List resend.api_key = "re_xxxxxxxxx" params: List[resend.Emails.SendParams] = [ { "from": "AcmeThanks for signing up!
", }, { "from": "AcmeYour order has been confirmed.
", } ] resend.Batch.send(params) ``` ```rb Ruby theme={null} require "resend" Resend.api_key = 're_xxxxxxxxx' params = [ { "from": "AcmeThanks for signing up!
", }, { "from": "AcmeYour order has been confirmed.
", } ] Resend::Batch.send(params) ``` ```go Go theme={null} package main import ( "context" "fmt" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") var batchEmails = []*resend.SendEmailRequest{ { From: "AcmeThanks for signing up!
", }, { From: "AcmeYour order has been confirmed.
", }, } sent, err := client.Batch.SendWithContext(ctx, batchEmails) if err != nil { panic(err) } fmt.Println(sent.Data) } ``` ```rust Rust theme={null} use resend_rs::types::CreateEmailBaseOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let emails = vec![ CreateEmailBaseOptions::new( "AcmeThanks for signing up!
"), CreateEmailBaseOptions::new( "AcmeYour order has been confirmed.
"), ]; let _emails = resend.batch.send(emails).await?; Ok(()) } ``` ```java Java theme={null} import com.resend.*; import java.util.Arrays; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateEmailOptions firstEmail = CreateEmailOptions.builder() .from("AcmeThanks for signing up!
") .build(); CreateEmailOptions secondEmail = CreateEmailOptions.builder() .from("AcmeYour order has been confirmed.
") .build(); CreateBatchEmailsResponse data = resend.batch().send( Arrays.asList(firstEmail, secondEmail) ); } } ``` ```csharp .NET theme={null} using Resend; IResend resend = ResendClient.Create("re_xxxxxxxxx"); var mail1 = new EmailMessage() { From = "AcmeThanks for signing up!
", }; var mail2 = new EmailMessage() { From = "AcmeYour order has been confirmed.
", }; var resp = await resend.EmailBatchAsync([mail1, mail2]); Console.WriteLine("Nr Emails={0}", resp.Content.Data.Count); ``` ```bash cURL theme={null} curl -X POST 'https://api.resend.com/emails/batch' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d $'[ { "from": "AcmeThanks for signing up!
" }, { "from": "AcmeYour order has been confirmed.
" } ]' ```it works!
', headers: { 'X-Entity-Ref-ID': 'xxx_xxxx', }, }); ``` ```php PHP {9} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->emails->send([ 'from' => 'Acmeit works!
', 'headers' => [ 'X-Entity-Ref-ID' => 'xxx_xxxx', ] ]); ``` ```python Python {11} theme={null} import resend resend.api_key = "re_xxxxxxxxx" params: resend.Emails.SendParams = { "from": "onboarding@resend.dev", "to": ["delivered@resend.dev"], "subject": "hi", "html": "it works!
", "headers": { "X-Entity-Ref-ID": "xxx_xxxx" } } email = resend.Emails.send(params) print(email) ``` ```rb Ruby {11} theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" params = { "from": "Acmeit works!
", "headers": { "X-Entity-Ref-ID": "123" }, } sent = Resend::Emails.send(params) puts sent ``` ```go Go {17} theme={null} import ( "fmt" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") params := &resend.SendEmailRequest{ From: "Acmeit works!
", Headers: map[string]string{ "X-Entity-Ref-ID": "xxx_xxxx", } } sent, err := client.Emails.SendWithContext(ctx, params) if err != nil { panic(err) } fmt.Println(sent.Id) } ``` ```rust Rust {14} theme={null} use resend_rs::types::{Attachment, CreateEmailBaseOptions, Tag}; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "Acmeit works!
") .with_header("X-Entity-Ref-ID", "xxx_xxxx"); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java {13} theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateEmailOptions params = CreateEmailOptions.builder() .from("Acmeit works!
") .headers(Map.of( "X-Entity-Ref-ID", "xxx_xxxx" )) .build(); CreateEmailResponse data = resend.emails().send(params); } } ``` ```csharp .NET {12-15} theme={null} using Resend; using System.Collections.Generic; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var message = new EmailMessage() { From = "Acmeit works!
", Headers = new Dictionaryit works!
", "headers": { "X-Entity-Ref-ID": "xxx_xxxx" } }' ```Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
Here is our inline logo
it works!
', }, { idempotencyKey: 'welcome-user/123456789', }, ); ``` ```php PHP {9} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->emails->send([ 'from' => 'Acmeit works!
', ], [ 'idempotency_key' => 'welcome-user/123456789', ]); ``` ```python Python {9} theme={null} params: resend.Emails.SendParams = { "from": "Acmeit works!
" } options: resend.Emails.SendOptions = { "idempotency_key": "welcome-user/123456789", } resend.Emails.send(params, options) ``` ```rb Ruby {9} theme={null} params = { "from": "Acmeit works!
" } Resend::Emails.send( params, options: { idempotency_key: "welcome-user/123456789" } ) ``` ```go Go {9} theme={null} ctx := context.TODO() params := &resend.SendEmailRequest{ From: "onboarding@resend.dev", To: []string{"delivered@resend.dev"}, Subject: "hello world", Html: "it works!
", } options := &resend.SendEmailOptions{ IdempotencyKey: "welcome-user/123456789", } _, err := client.Emails.SendWithOptions(ctx, params, options) if err != nil { panic(err) } ``` ```rust Rust {14} theme={null} use resend_rs::types::CreateEmailBaseOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "Acmeit works!
") .with_idempotency_key("welcome-user/123456789"); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java {9} theme={null} CreateEmailOptions params = CreateEmailOptions.builder() .from("Acmeit works!
") .build(); RequestOptions options = RequestOptions.builder() .setIdempotencyKey("welcome-user/123456789").build(); CreateEmailResponse data = resend.emails().send(params, options); ``` ```csharp C# {11} theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var key = IdempotencyKey.Newit works!
", } ); Console.WriteLine( "Email Id={0}", resp.Content ); ``` ```bash cURL {4} theme={null} curl -X POST 'https://api.resend.com/emails' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -H 'Idempotency-Key: welcome-user/123456789' \ -d $'{ "from": "Acmeit works!
" }' ``` ```yaml SMTP {4} theme={null} From: Acmeit works!
```it works!
', }, ], { idempotencyKey: 'team-quota/123456789', }, ); ``` ```php PHP {19} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->batch->send( [ [ 'from' => 'Acmeit works!
', ] ], [ 'idempotency_key' => 'team-quota/123456789', ] ); ``` ```py Python {22} theme={null} import resend from typing import List resend.api_key = "re_xxxxxxxxx" params: List[resend.Emails.SendParams] = [ { "from": "Acmeit works!
", } ] options: resend.Batch.SendOptions = { "idempotency_key": "team-quota/123456789", } resend.Batch.send(params, options) ``` ```rb Ruby {22} theme={null} require "resend" Resend.api_key = 're_xxxxxxxxx' params = [ { "from": "Acmeit works!
", } ] Resend::Batch.send( params, options: { idempotency_key: "team-quota/123456789" } ) ``` ```go Go {32} theme={null} package examples import ( "fmt" "os" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") var batchEmails = []*resend.SendEmailRequest{ { From: "Acmeit works!
", }, } options := &resend.BatchSendEmailOptions{ IdempotencyKey: "team-quota/123456789", } sent, err := client.Batch.SendWithOptions(ctx, batchEmails, options) if err != nil { panic(err) } fmt.Println(sent.Data) } ``` ```rust Rust {23} theme={null} use resend_rs::types::CreateEmailBaseOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let emails = vec![ CreateEmailBaseOptions::new( "Acmeit works!
"), ]; let _emails = resend.batch.send_with_idempotency_key(emails, "team-quota/123456789").await?; Ok(()) } ``` ```java Java {23} theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateEmailOptions firstEmail = CreateEmailOptions.builder() .from("Acmeit works!
") .build(); CreateBatchEmailsResponse data = resend.batch().send( Arrays.asList(firstEmail, secondEmail), Map.of("idempotency_key", "team-quota/123456789") ); } } ``` ```csharp .NET {5} theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var key = IdempotencyKey.Newit works!
", }; var mail2 = new EmailMessage() { From = "Acmeit works!
", }; var resp = await resend.EmailBatchAsync(key, [ mail1, mail2 ] ); Console.WriteLine( "Nr Emails={0}", resp.Content.Count ); ``` ```bash cURL {4} theme={null} curl -X POST 'https://api.resend.com/emails/batch' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -H 'Idempotency-Key: team-quota/123456789' \ -d $'[ { "from": "Acmeit works!
" } ]' ```it works!
', scheduledAt: 'in 1 min', }); ``` ```php PHP {8} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->emails->send([ 'from' => 'Acmeit works!
', 'scheduled_at' => 'in 1 min' ]); ``` ```python Python {10} theme={null} import resend resend.api_key = "re_xxxxxxxxx" params: resend.Emails.SendParams = { "from": "Acmeit works!
", "scheduled_at": "in 1 min" } resend.Emails.send(params) ``` ```rb Ruby {10} theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" params = { "from": "Acmeit works!
", "scheduled_at": "in 1 min" } Resend::Emails.send(params) ``` ```go Go {16} theme={null} import ( "fmt" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") params := &resend.SendEmailRequest{ From: "Acmeit works!
", ScheduledAt: "in 1 min" } sent, err := client.Emails.SendWithContext(ctx, params) if err != nil { panic(err) } fmt.Println(sent.Id) } ``` ```rust Rust {14} theme={null} use resend_rs::types::CreateEmailBaseOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "Acmeit works!
") .with_scheduled_at("in 1 min"); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java {12} theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateEmailOptions params = CreateEmailOptions.builder() .from("Acmeit works!
") .scheduledAt("in 1 min") .build(); CreateEmailResponse data = resend.emails().send(params); } } ``` ```csharp .NET {11} theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var resp = await resend.EmailSendAsync( new EmailMessage() { From = "Acmeit works!
", MomentSchedule = "in 1 min", } ); Console.WriteLine( "Email Id={0}", resp.Content ); ``` ```bash cURL {9} theme={null} curl -X POST 'https://api.resend.com/emails' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d $'{ "from": "Acmeit works!
", "scheduled_at": "in 1 min" }' ```it works!
', scheduledAt: oneMinuteFromNow, }); ``` ```php PHP {3} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $oneMinuteFromNow = (new DateTime())->modify('+1 minute')->format(DateTime::ISO8601); $resend->emails->send([ 'from' => 'Acmeit works!
', 'scheduled_at' => $oneMinuteFromNow ]); ``` ```python Python {6} theme={null} import resend from datetime import datetime, timedelta resend.api_key = "re_xxxxxxxxx" one_minute_from_now = (datetime.now() + timedelta(minutes=1)).isoformat() params: resend.Emails.SendParams = { "from": "Acmeit works!
", "scheduled_at": one_minute_from_now } resend.Emails.send(params) ``` ```rb Ruby {5} theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" one_minute_from_now = (Time.now + 1 * 60).strftime("%Y-%m-%dT%H:%M:%S.%L%z") params = { "from": "Acmeit works!
", "scheduled_at": one_minute_from_now } Resend::Emails.send(params) ``` ```go Go {12} theme={null} import ( "fmt" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") oneMinuteFromNow := time.Now().Add(time.Minute * time.Duration(1)) oneMinuteFromNowISO := oneMinuteFromNow.Format("2006-01-02T15:04:05-0700") params := &resend.SendEmailRequest{ From: "Acmeit works!
", ScheduledAt: oneMinuteFromNowISO } sent, err := client.Emails.SendWithContext(ctx, params) if err != nil { panic(err) } fmt.Println(sent.Id) } ``` ```rust Rust {12-15} theme={null} use chrono::{Local, TimeDelta}; use resend_rs::types::CreateEmailBaseOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "Acmeit works!
") .with_scheduled_at(&one_minute_from_now); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java {7-10} theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); String oneMinuteFromNow = Instant .now() .plus(1, ChronoUnit.MINUTES) .toString(); CreateEmailOptions params = CreateEmailOptions.builder() .from("Acmeit works!
") .scheduledAt(oneMinuteFromNow) .build(); CreateEmailResponse data = resend.emails().send(params); } } ``` ```csharp .NET {11} theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var resp = await resend.EmailSendAsync( new EmailMessage() { From = "Acmeit works!
", MomentSchedule = DateTime.UtcNow.AddMinutes( 1 ), } ); Console.WriteLine( "Email Id={0}", resp.Content ); ``` ```bash cURL {9} theme={null} curl -X POST 'https://api.resend.com/emails' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d $'{ "from": "Acmeit works!
", "scheduled_at": "2024-08-20T11:52:01.858Z" }' ```it works!
', tags: [ { name: 'category', value: 'confirm_email', }, ], }); ``` ```php PHP {8-13} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->emails->send([ 'from' => 'Acmeit works!
', 'tags' => [ [ 'name' => 'category', 'value' => 'confirm_email', ], ] ]); ``` ```python Python {10-12} theme={null} import resend resend.api_key = "re_xxxxxxxxx" params: resend.Emails.SendParams = { "from": "Acmeit works!
", "tags": [ {"name": "category", "value": "confirm_email"}, ], } email = resend.Emails.send(params) print(email) ``` ```rb Ruby {10-12} theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" params = { "from": "Acmeit works!
", "tags": [ {"name": "category", "value": "confirm_email"} ] } sent = Resend::Emails.send(params) puts sent ``` ```go Go {16} theme={null} import ( "fmt" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") params := &resend.SendEmailRequest{ From: "Acmeit works!
", Subject: "hello world", Tags: []resend.Tag{{Name: "category", Value: "confirm_email"}}, } sent, err := client.Emails.SendWithContext(ctx, params) if err != nil { panic(err) } fmt.Println(sent.Id) } ``` ```rust Rust {14} theme={null} use resend_rs::types::{CreateEmailBaseOptions, Tag}; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "Acmeit works!
") .with_tag(Tag::new("category", "confirm_email")); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java {17} theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); Tag tag = Tag.builder() .name("category") .value("confirm_email") .build(); SendEmailRequest sendEmailRequest = SendEmailRequest.builder() .from("Acmeit works!
") .tags(tag) .build(); SendEmailResponse data = resend.emails().send(sendEmailRequest); } } ``` ```csharp .NET {12} theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var resp = await resend.EmailSendAsync( new EmailMessage() { From = "Acmeit works!
", ReplyTo = "onboarding@resend.dev", Tags = new Listit works!
", "tags": [ { "name": "category", "value": "confirm_email" } ] }' ```it works!
', tags: [ { name: 'category', value: 'confirm_email', }, ], }, ]); ``` ```php PHP {9-13,21-25} theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->batch->send([ [ 'from' => 'Acmeit works!
', 'tags' => [ [ 'name' => 'category', 'value' => 'confirm_email' ] ] ] ]); ``` ```py Python {12-17,24-29} theme={null} import resend from typing import List resend.api_key = "re_xxxxxxxxx" params: List[resend.Emails.SendParams] = [ { "from": "Acmeit works!
", "tags": [ { "name": "category", "value": "confirm_email" } ] } ] resend.Batch.send(params) ``` ```rb Ruby {11-16,23-28} theme={null} require "resend" Resend.api_key = 're_xxxxxxxxx' params = [ { "from": "Acmeit works!
", "tags": [ { "name": "category", "value": "confirm_email" } ] } ] Resend::Batch.send(params) ``` ```go Go {22,29} theme={null} package examples import ( "fmt" "os" "github.com/resend/resend-go/v3" ) func main() { ctx := context.TODO() client := resend.NewClient("re_xxxxxxxxx") var batchEmails = []*resend.SendEmailRequest{ { From: "Acmeit works!
", Tags: []resend.Tag{{Name: "category", Value: "confirm_email"}}, }, } sent, err := client.Batch.SendWithContext(ctx, batchEmails) if err != nil { panic(err) } fmt.Println(sent.Data) } ``` ```rust Rust {15,22} theme={null} use resend_rs::types::CreateEmailBaseOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let emails = vec![ CreateEmailBaseOptions::new( "Acmeit works!
") .with_tag(Tag::new("category", "confirm_email")), ]; let _emails = resend.batch.send(emails).await?; Ok(()) } ``` ```java Java {12-15,23-26} theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateEmailOptions firstEmail = CreateEmailOptions.builder() .from("Acmeit works!
") .tags(Tag.builder() .name("category") .value("confirm_email") .build()) .build(); CreateBatchEmailsResponse data = resend.batch().send( Arrays.asList(firstEmail, secondEmail) ); } } ``` ```csharp .NET {11,20} theme={null} using Resend; IResend resend = ResendClient.Create( "re_xxxxxxxxx" ); // Or from DI var mail1 = new EmailMessage() { From = "Acmeit works!
", Tags = new Listit works!
", Tags = new Listit works!
", "tags": [ { "name": "category", "value": "confirm_email" } ] } ]' ```Thanks for your email!
', headers: { 'In-Reply-To': event.data.message_id, }, attachments, }); return NextResponse.json(data); } return NextResponse.json({}); }; ``` If you're replying multiple times within the same thread, make sure to also append the previous `message_id`s to the `References` header, separated by spaces. This helps email clients maintain the correct threading structure. ```js theme={null} const previousReferences = ['Thanks for your email!
', headers: { 'In-Reply-To': event.data.message_id, 'References': [...previousReferences, event.data.message_id].join(' '), }, attachments, }); ``` # Managing Segments Source: https://resend.com/docs/dashboard/segments/introduction Learn how to create, retrieve, and delete segments. Segments are used to group and manage your [Contacts](/dashboard/audiences/contacts). Segments are not visible to your Contacts, but are used for your own internal Contact organization. ## Send emails to your Segment Segments were designed to be used in conjunction with [Broadcasts](/dashboard/broadcasts/introduction). You can send a Broadcast to an Segment from the Resend dashboard or from the Broadcast API. ### From Resend's no-code editor You can send emails to your Segment by creating a new Broadcast and selecting the Segment you want to send it to.Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
', variables: [ { key: 'PRODUCT', type: 'string', fallbackValue: 'item', }, { key: 'PRICE', type: 'number', fallbackValue: 20, }, ], }); ``` ```php PHP theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->templates->create([ 'name' => 'order-confirmation', 'from' => 'Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
', 'variables' => [ [ 'key' => 'PRODUCT', 'type' => 'string', 'fallback_value' => 'item' ], [ 'key' => 'PRICE', 'type' => 'number', 'fallback_value' => 49.99 ] ] ]); ``` ```py Python theme={null} import resend resend.api_key = "re_xxxxxxxxx" params: resend.Templates.CreateParams = { "name": "order-confirmation", "from": "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", "variables": [ { "key": "PRODUCT", "type": "string", "fallback_value": "item", }, { "key": "PRICE", "type": "number", "fallback_value": 20, }, ], } resend.Templates.create(params) ``` ```ruby Ruby theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" Resend::Templates.create( name: "order-confirmation", from: "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", variables: [ { key: "PRODUCT", type: "string", fallback_value: "item" }, { key: "PRICE", type: "number", fallback_value: 20 } ] ) ``` ```go Go theme={null} import "github.com/resend/resend-go/v3" client := resend.NewClient("re_xxxxxxxxx") template, err := client.Templates.Create(&resend.CreateTemplateRequest{ Name: "order-confirmation", From: "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", Variables: []*resend.TemplateVariable{ { Key: "PRODUCT", Type: resend.VariableTypeString, FallbackValue: "item", }, { Key: "PRICE", Type: resend.VariableTypeNumber, FallbackValue: 20, }, }, }) ``` ```rust Rust theme={null} use resend_rs::{ types::{CreateTemplateOptions, Variable, VariableType}, Resend, Result, }; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let name = "order-confirmation"; let from = "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
"; let variables = [ Variable::new("PRODUCT", VariableType::String).with_fallback("item"), Variable::new("PRICE", VariableType::Number).with_fallback(20) ]; let opts = CreateTemplateOptions::new(name, from, subject) .with_html(html) .with_variables(&variables); let template = resend.templates.create(opts).await?; let _published = resend.templates.publish(&template.id).await?; Ok(()) } ``` ```java Java theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateTemplateOptions params = CreateTemplateOptions.builder() .name("order-confirmation") .from("Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
") .addVariable(new Variable("PRODUCT", VariableType.STRING, "item")) .addVariable(new Variable("PRICE", VariableType.NUMBER, 20)) .build(); CreateTemplateResponseSuccess data = resend.templates().create(params); } } ``` ```csharp .NET theme={null} using Resend; IResend resend = ResendClient.Create("re_xxxxxxxxx"); var variables = new ListName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", Variables = variables, } ); Console.WriteLine($"Template Id={resp.Content}"); ``` ```bash cURL theme={null} curl -X POST 'https://api.resend.com/templates' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d $'{ "name": "order-confirmation", "from": "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", "variables": [ { "key": "PRODUCT", "type": "string", "fallback_value": "item" }, { "key": "PRICE", "type": "number", "fallback_value": 20 } ] }' ```
You can create a Template from an existing Broadcast. Locate your desired
Broadcast in the [Broadcast dashboard](https://resend.com/broadcasts), click
the more options button
You can also define custom variables via the API. The payload can optionally include variables to be used in the Template.
Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
', variables: [ { key: 'PRODUCT', type: 'string', fallbackValue: 'item', }, { key: 'PRICE', type: 'number', fallbackValue: 25, }, ], }); ``` ```php PHP theme={null} $resend = Resend::client('re_xxxxxxxxx'); $resend->templates->create([ 'name' => 'order-confirmation', 'html' => 'Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
', 'variables' => [ [ 'key' => 'PRODUCT', 'type' => 'string', 'fallback_value' => 'item', ], [ 'key' => 'PRICE', 'type' => 'number', 'fallback_value' => 25, ] ], ]); ``` ```py Python theme={null} import resend resend.api_key = "re_xxxxxxxxx" resend.Templates.create({ "name": "order-confirmation", "html": "Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
", "variables": [ { "key": "PRODUCT", "type": "string", "fallback_value": "item", }, { "key": "PRICE", "type": "number", "fallback_value": 25, } ], }) ``` ```ruby Ruby theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" Resend::Templates.create( name: "order-confirmation", html: "Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
", variables: [ { key: "PRODUCT", type: "string", fallback_value: "item" }, { key: "PRICE", type: "number", fallback_value: 25 } ] ) ``` ```go Go theme={null} import ( "context" "github.com/resend/resend-go/v3" ) func main() { client := resend.NewClient("re_xxxxxxxxx") template, err := client.Templates.CreateWithContext(context.TODO(), &resend.CreateTemplateRequest{ Name: "order-confirmation", Html: "Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
", Variables: []*resend.TemplateVariable{ { Key: "PRODUCT", Type: resend.VariableTypeString, FallbackValue: "item", }, { Key: "PRICE", Type: resend.VariableTypeNumber, FallbackValue: 25, } }, }) } ``` ```rust Rust theme={null} use resend_rs::{ types::{CreateTemplateOptions, Variable, VariableType}, Resend, Result, }; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let name = "order-confirmation"; let html = "Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
"; let variables = [ Variable::new("PRODUCT", VariableType::String).with_fallback("item"), Variable::new("PRICE", VariableType::Number).with_fallback(25) ]; let opts = CreateTemplateOptions::new(name, html).with_variables(&variables); let template = resend.templates.create(opts).await?; let _published = resend.templates.publish(&template.id).await?; Ok(()) } ``` ```java Java theme={null} import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_xxxxxxxxx"); CreateTemplateOptions params = CreateTemplateOptions.builder() .name("order-confirmation") .html("Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
") .addVariable(new Variable("PRODUCT", VariableType.STRING, "item")) .addVariable(new Variable("PRICE", VariableType.NUMBER, 25)) .build(); CreateTemplateResponseSuccess data = resend.templates().create(params); } } ``` ```csharp .NET theme={null} using Resend; IResend resend = ResendClient.Create("re_xxxxxxxxx"); var variables = new ListName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", "variables": [ { "key": "PRODUCT", "type": "string", "fallback_value": "item" }, { "key": "PRICE", "type": "number", "fallback_value": 25 } ] }' ```Name: {{{PRODUCT}}}
Total: {{{PRICE}}}
", variables: [ { key: 'PRODUCT', type: 'string', fallbackValue: 'item' }, { key: 'PRICE', type: 'number', fallbackValue: 20 } ] }); // Publish template await resend.templates.publish('template_id'); // Or create and publish a template in one step await resend.templates.create({ ... }).publish(); ``` ```php PHP theme={null} $resend = Resend::client('re_xxxxxxxxx'); // Create template $resend->templates->create([ 'name' => 'order-confirmation', 'from' => 'Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", 'variables' => [ [ 'key' => 'PRODUCT', 'type' => 'string', 'fallbackValue' => 'item' ], [ 'key' => 'PRICE', 'type' => 'number', 'fallbackValue' => 49.99 ] ] ]); // Publish template $resend->templates->publish('template_id'); ``` ```py Python theme={null} import resend resend.api_key = "re_xxxxxxxxx" // Create template params: resend.Templates.CreateParams = { "name": "order-confirmation", "from": "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", "variables": [ { "key": "PRODUCT", "type": "string", "fallbackValue": "item" }, { "key": "PRICE", "type": "number", "fallbackValue": 20 }, ] } resend.Templates.create(params) // Publish template resend.Templates.publish('template_id'); ``` ```ruby Ruby theme={null} require "resend" Resend.api_key = "re_xxxxxxxxx" // Create template params = { "name": 'order-confirmation', "from": 'Resend StoreName: #{{{PRODUCT}}}
Total: #{{{PRICE}}}
", "variables": [{ "key": 'PRODUCT', "type": 'string', "fallbackValue": 'item' }, { "key": 'PRICE', "type": 'number', "fallbackValue": 20 } ] } Resend::Templates.create(params) // Publish template Resend::Templates.publish('template_id'); ``` ```go Go theme={null} import "github.com/resend/resend-go/v2" client := resend.NewClient("re_xxxxxxxxx") // Create template params := &resend.CreateTemplateRequest{ Name: "order-confirmation", From: "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", Variables: []resend.TemplateVariable{ { Key: "PRODUCT", Type: "string", FallbackValue: "item", }, { Key: "PRICE", Type: "number", FallbackValue: 20, }, }, } template, _ := client.Templates.Create(params) // Publish template client.Templates.Publish(template.Id) ``` ```rust Rust theme={null} use resend_rs::{types::CreateTemplateOptions, Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); // Create template let name = "order-confirmation"; let from = "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
"; let variables = vec![ TemplateVariable { key: "PRODUCT", type_: "string", fallback_value: Some("item"), }, TemplateVariable { key: "PRICE", type_: "number", fallback_value: Some(20), }, ]; let opts = CreateTemplateOptions::new(name, from, subject) .with_html(html) .with_variables(variables); let _template = resend.templates.create(opts).await?; // Publish template resend.templates.publish(&template.id).await?; Ok(()) } ``` ```java Java theme={null} Resend resend = new Resend("re_xxxxxxxxx"); // Create template ListName: {{{PRODUCT}}}
Total: {{{PRICE}}}
") .variables(variables) .build(); CreateTemplateResponseSuccess data = resend.templates().create(params); // Publish template resend.templates().publish(data.content); ``` ```csharp .NET theme={null} using Resend; IResend resend = ResendClient.Create("re_xxxxxxxxx"); // Create template var variables = new ListName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", Variables = variables, } ); // Publish template await resend.TemplatePublishAsync(resp.Content); Console.WriteLine($"Template Id={resp.Content}"); ``` ```bash cURL theme={null} # Create template curl -X POST 'https://api.resend.com/templates' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' \ -d $'{ "name": "order-confirmation", "from": "Resend StoreName: {{{PRODUCT}}}
Total: {{{PRICE}}}
", "variables": [ { "key": "PRODUCT", "type": "string", "fallbackValue": "item" }, { "key": "PRICE", "type": "number", "fallbackValue": 20 } ] }' # Publish template curl -X POST 'https://api.resend.com/templates/{template_id}/publish' \ -H 'Authorization: Bearer re_xxxxxxxxx' \ -H 'Content-Type: application/json' ```Hello World
', }); ``` **Option 2: Delete and re-add the domain** 1. Delete the domain you've added in Resend 2. Add and verify the domain that matches what you're using in your API requestThank you for joining our service.
Your account email: {{ user_email }}
``` Then render and send the template: ```py views.py theme={null} from django.core.mail import EmailMessage from django.http import JsonResponse from django.template.loader import render_to_string def send_template_email(request): html_content = render_to_string('emails/welcome.html', { 'user_name': 'Django Developer', 'user_email': 'delivered@resend.dev', 'dashboard_url': 'https://example.com/dashboard', }) message = EmailMessage( subject="Welcome to Our Service!", body=html_content, from_email="AcmeYou have successfully signed up to example.com,
To log in to the site, just follow this link: <%= @url %>.
Thanks for joining and have a great day!
``` Initialize your `UserMailer` class. This should return a `UserMailer` instance. ```rb theme={null} u = User.new name: "derich" mailer = UserMailer.with(user: u).welcome_email # => #You have successfully signed up to example.com,
To log in to the site, just follow this link: <%= @url %>.
Thanks for joining and have a great day!
``` Initialize your `UserMailer` class. This should return a `UserMailer` instance. ```rb theme={null} u = User.new name: "derich" mailer = UserMailer.with(user: u).welcome_email # => #it works!
``` Learn more about [idempotency keys](/dashboard/emails/idempotency-keys). ## Custom Headers If your SMTP client supports it, you can add custom headers to your emails. Here are some common use cases for custom headers: * Prevent threading on Gmail with the `X-Entity-Ref-ID` header * Include a shortcut for users to unsubscribe with the `List-Unsubscribe` header ## FAQ Once configured, you should be able to start sending emails via SMTP. Below are some frequently asked questions:Hello world
', }); if (error) { return Response.json({ error }, { status: 500 }); } return Response.json({ data }); } catch (error) { return Response.json({ error }, { status: 500 }); } } ```