### Install Resend Ruby Gem Source: https://github.com/resend/resend-ruby/blob/main/README.md Install the Resend Ruby SDK using RubyGems or add it to your Gemfile. ```bash gem install resend ``` ```ruby gem 'resend' ``` -------------------------------- ### Rails Mailer Example with Resend Source: https://github.com/resend/resend-ruby/blob/main/README.md Example of a Rails mailer using Resend for delivery, including defining a welcome email and delivering it. ```ruby #/app/mailers/user_mailer class UserMailer < ApplicationMailer default from: 'you@yourdomain.io' def welcome_email @user = params[:user] @url = 'http://example.com/login' mail(to: ["example2@mail.com", "example1@mail.com"], subject: 'Hello from Resend') end end # anywhere in the app u = User.new name: "derich" mailer = UserMailer.with(user: u).welcome_email mailer.deliver_now! # => {:id=>"b8f94710-0d84-429c-925a-22d3d8f86916", from: 'you@yourdomain.io', to: ["example2@mail.com", "example1@mail.com"]} ``` -------------------------------- ### Install Resend Ruby Gem Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/README.md Add the Resend gem to your project's Gemfile for installation. ```ruby gem 'resend' ``` -------------------------------- ### Send Email with ActionMailer and Resend Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Example of a Rails mailer class and how to send an email using Resend. ```ruby # app/mailers/user_mailer.rb class UserMailer < ApplicationMailer default from: 'notifications@example.com' def welcome_email @user = params[:user] mail(to: @user.email, subject: 'Welcome') end end # In your app UserMailer.with(user: user).welcome_email.deliver_now! ``` -------------------------------- ### Send Email with Resend Ruby SDK Source: https://github.com/resend/resend-ruby/blob/main/README.md Example of sending an email using the Resend Ruby SDK, including parameters for sender, recipient, subject, and HTML content. ```ruby require "resend" Resend.api_key = ENV["RESEND_API_KEY"] params = { "from": "onboarding@resend.dev", "to": ["delivered@resend.dev", "your@email.com"], "html": "

Hello World

", "subject": "Hey" } r = Resend::Emails.send(params) puts r ``` -------------------------------- ### Configure API Key (Dynamic) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/README.md Set your Resend API key using a lambda for dynamic loading. This is useful for fetching the key at runtime, for example, from environment variables. ```ruby # Dynamic (lazy loading) Resend.api_key = -> { ENV["RESEND_API_KEY"] } ``` -------------------------------- ### Set and Get Global API Key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Demonstrates how to set and retrieve the global Resend API key. The API key can be set as a static string or a Proc for dynamic loading. ```Ruby Resend.api_key = "re_..." api_key = Resend.api_key ``` -------------------------------- ### Pagination with Cursors Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md List methods in the Resend Ruby SDK support cursor-based pagination. This example demonstrates how to fetch a list of emails and retrieve the next cursor for subsequent requests. ```APIDOC ## Pagination All list methods support cursor-based pagination: ```ruby response = Resend::Emails.list(limit: 10, after: "cursor_123") emails = response[:data] next_cursor = response[:cursor] ``` Parameters: - `:limit` - Items per page (max 100, default 20) - `:after` - Get items after this cursor - `:before` - Get items before this cursor ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Retrieve a specific automation using its ID. ```APIDOC ## get ### Description Retrieve an automation. ### Method ```ruby def get(automation_id = "") ``` ### Parameters #### Path Parameters - **automation_id** (String) - Required - The automation ID ### Response #### Success Response - **automation** (Resend::Response) - automation object ### Request Example ```ruby response = Resend::Automations.get("auto_123") ``` ``` -------------------------------- ### Optional Request Options Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md Certain methods in the Resend Ruby SDK accept optional request configuration options. This example shows how to use `idempotency_key` to prevent duplicate requests and `batch_validation` for batch operations. ```APIDOC ## Request Options Some methods accept optional request configuration: ```ruby Resend::Emails.send(params, options: { idempotency_key: "unique_123" # Prevent duplicates }) Resend::Batch.send(emails, options: { batch_validation: "permissive" # Return partial results }) ``` ``` -------------------------------- ### Error Handling with Resend SDK Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md The Resend Ruby SDK categorizes errors by HTTP status codes. This example shows how to rescue specific Resend errors, such as RateLimitExceededError, and implement retry logic. ```APIDOC ## Error Handling Errors are categorized by HTTP status code: | Code | Class | Meaning | |------|-------|---------| | 400 | InvalidRequestError | Bad request | | 401 | InvalidRequestError | Unauthorized | | 404 | InvalidRequestError | Not found | | 422 | InvalidRequestError | Validation failed | | 429 | RateLimitExceededError | Rate limited | | 500 | InternalServerError | Server error | **Example:** ```ruby begin Resend::Emails.send(params) rescue Resend::Error::RateLimitExceededError => e sleep(e.retry_after) retry end ``` ``` -------------------------------- ### Initialize Resend Client and Send Email Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Demonstrates how to create a new Resend client instance with an API key and use it to send an email. The client instance includes modules for making API calls. ```Ruby client = Resend::Client.new("re_123456") # Client includes Resend::Emails module response = client.send({ from: "sender@example.com", to: ["recipient@example.com"], subject: "Hello", html: "

Hi

" }) ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Create a new automation with specified configuration. ```APIDOC ## create ### Description Create a new automation. ### Method ```ruby def create(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Automation config: `:name`, `:trigger`, `:actions` ### Response #### Success Response - **automation** (Resend::Response) - automation object with `:id` ### Request Example ```ruby response = Resend::Automations.create({ name: "Welcome Series", trigger: { event: "user.signed_up" }, actions: [] }) ``` ``` -------------------------------- ### Configure Resend SDK using a Block Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Illustrates configuring the Resend SDK using the `configure` method or its alias `config` with a block. This is useful for setting configuration options like the API key. ```Ruby require "resend" Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end # or use the alias Resend.config do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` -------------------------------- ### Get a Specific Received Email Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Retrieve a single received email by its ID. Optionally, specify `:html_format` to get the email in 'sanitized' or 'raw' HTML format. ```ruby response = Resend::Emails::Receiving.get( "4ef9a417-02e9-4d39-ad75-9611e0fcc33c", html_format: "sanitized" ) ``` -------------------------------- ### Configure Resend SDK with API Key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Shows how to configure the Resend SDK globally using a block, setting the API key either statically or dynamically from environment variables or application context. ```Ruby require "resend" # Static API key Resend.api_key = "re_123456" # Dynamic API key from environment Resend.api_key = -> { ENV["RESEND_API_KEY"] } # Dynamic API key from application context Resend.api_key = -> { Current.user.resend_api_key } ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a specific segment by its ID. ```APIDOC ## get(segment_id = "") ### Description Retrieves a specific segment by its ID. ### Method ```ruby def get(segment_id = "") ``` ### Parameters #### Path Parameters - **segment_id** (String) - Required - The segment ID ### Request Example ```ruby response = Resend::Segments.get("segment_123") ``` ### Response #### Success Response - (segment object) #### Response Example (Resend::Response object containing segment data) ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a specific sending domain by its ID. ```APIDOC ## get(domain_id = "") ### Description Retrieves a specific sending domain. ### Method ```ruby def get(domain_id = "") ``` ### Parameters #### Path Parameters - **domain_id** (String) - Required - The domain ID ### Request Example ```ruby response = Resend::Domains.get("domain_123") ``` ### Response #### Success Response - **domain** (Resend::Response) - domain object ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Creates a new email preference topic. Requires a hash containing the topic's name. ```APIDOC ## create ### Description Creates a new email preference topic. ### Method Ruby Method ### Signature ```ruby def create(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Topic data: `:name` (required) ### Request Example ```ruby response = Resend::Topics.create({ name: "Marketing Updates" }) ``` ### Response #### Success Response - **topic object** (Resend::Response) - topic object with `:id` ### Response Example ```json { "id": "topic_abc123" } ``` ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Retrieve a single attachment from a received email. ```APIDOC ## get(params = {}) ### Description Retrieve a single attachment from a received email. ### Method ```ruby def get(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Parameters with `:id` and `:email_id` ### Request Example ```ruby response = Resend::Emails::Receiving::Attachments.get( id: "2a0c9ce0-3112-4728-976e-47ddcd16a318", email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" ) ``` ### Response #### Success Response - **attachment object** (Resend::Response) - Description ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Creates a new API key for your Resend account. Requires a name and optionally accepts permissions. ```APIDOC ## create(params) ### Description Create a new API key. ### Method ```ruby def create(params) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - API key config: `:name` (required), `:permissions` ### Request Example ```ruby response = Resend::ApiKeys.create({ name: "Production API Key" }) api_token = response[:token] ``` ### Response #### Success Response - **token** (string) - The generated API key token. #### Response Example ```json { "token": "key_..." } ``` ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Creates a new sending domain. Requires a hash of parameters including the domain name. ```APIDOC ## create(params) ### Description Creates a new sending domain. ### Method ```ruby def create(params) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Domain data: `:domain` (required) ### Request Example ```ruby response = Resend::Domains.create({ domain: "mail.example.com" }) ``` ### Response #### Success Response - **domain** (Resend::Response) - domain object with `:id` ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a specific email preference topic by its ID. ```APIDOC ## get ### Description Retrieves a specific email preference topic by its ID. ### Method Ruby Method ### Signature ```ruby def get(topic_id = "") ``` ### Parameters #### Path Parameters - **topic_id** (String) - Required - The topic ID ### Request Example ```ruby response = Resend::Topics.get("topic_123") ``` ### Response #### Success Response - **topic object** (Resend::Response) - The topic object ### Response Example ```json { "id": "topic_123", "name": "Marketing Updates" } ``` ``` -------------------------------- ### Get Response Data Values Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Retrieves an array of all values present in the response data. ```ruby def values end ``` -------------------------------- ### Configure API Key with Block Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Configure the API key using a block, often loading it from an environment variable. ```ruby require "resend" Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` -------------------------------- ### Get Response Data Keys Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Retrieves an array of all keys present in the response data. ```ruby response = Resend::Emails.send(params) response.keys # => [:id, :from, :to, ...] ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Retrieve a single contact import by its ID. Provides status information about the import process. ```APIDOC ## GET /contacts/imports/{id} ### Description Retrieve a single contact import by its ID. Provides status information about the import process. ### Method GET ### Endpoint /contacts/imports/{id} ### Parameters #### Path Parameters - **id** (String) - Required - The contact import ID. ### Response #### Success Response (200) - **status** (String) - The status of the import (e.g., queued, in_progress, completed, failed). ``` -------------------------------- ### Configure Resend in Rails Initializer Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Set up the Resend API key in a Rails initializer file. ```ruby # config/initializers/resend.rb Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` -------------------------------- ### Configure API Key (Configure Block) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/README.md Configure the API key using a block. This provides a clear and organized way to set configuration options, including the API key. ```ruby # Using configure block Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a specific contact property using its unique ID. Returns the property object upon successful retrieval. ```APIDOC ## get ### Description Retrieve a contact property. ### Method Ruby Method ### Parameters #### Path Parameters - **contact_property_id** (String) - Required - The property ID ### Request Example ```ruby response = Resend::ContactProperties.get("b6d24b8e-af0b-4c3c-be0c-359bbd97381e") ``` ### Response #### Success Response - **property object** (Resend::Response) ``` -------------------------------- ### Get Specific Automation Run Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Retrieves the details of a specific automation run using both the automation ID and the run ID. ```APIDOC ## Get Specific Automation Run ### Description Retrieves a specific automation run by its ID and the parent automation's ID. ### Method `Resend::Automations::Runs.get` ### Parameters #### Path Parameters - **automation_id** (String) - Required - The ID of the automation. - **run_id** (String) - Required - The ID of the specific run. ### Request Example ```ruby response = Resend::Automations::Runs.get("auto_123", "run_456") ``` ### Response #### Success Response - Returns a `Resend::Response` object containing the run details. ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md List automations with optional pagination parameters. ```APIDOC ## list ### Description List automations with pagination. ### Method ```ruby def list(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Optional - Pagination: `:limit`, `:after`, `:before` ### Response #### Success Response - **automations** (Resend::Response) - paginated list ### Request Example ```ruby response = Resend::Automations.list() ``` ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Retrieve a single email by its unique ID. This is useful for checking the status or details of a previously sent or scheduled email. ```APIDOC ## get ### Description Retrieve a single email by its unique ID. This is useful for checking the status or details of a previously sent or scheduled email. ### Method GET ### Endpoint /emails/{email_id} ### Parameters #### Path Parameters - **email_id** (String) - Required - The email ID to retrieve #### Query Parameters None #### Request Body None ### Request Example ```ruby Resend::Emails.get("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794") ``` ### Response #### Success Response (200) - **id** (String) - The email ID. - **from** (String) - The sender's email address. #### Response Example ```json { "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", "from": "onboarding@resend.dev" } ``` ``` -------------------------------- ### List Topics with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a paginated list of email preference topics. Optional parameters for pagination include :limit, :after, and :before. ```ruby response = Resend::Topics.list() ``` -------------------------------- ### get(params = {}) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Retrieves a single contact by either their ID or email address. An optional audience ID can be provided to filter results. ```APIDOC ## get(params = {}) ### Description Retrieves a single contact by either their ID or email address. An optional audience ID can be provided to filter results. ### Method ```ruby def get(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Parameters: `:id` or `:email` (required), `:audience_id` (optional) ### Request Example ```ruby response = Resend::Contacts.get(id: "contact_123") response = Resend::Contacts.get(email: "steve@apple.com") response = Resend::Contacts.get( id: "contact_123", audience_id: "audience_456" ) ``` ### Response #### Success Response - **contact object** (object) - The retrieved contact details. ``` -------------------------------- ### Resend.api_key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Get or set the Resend API key globally. This can be set as a static string or a Proc for dynamic loading at request time. ```APIDOC ## Resend.api_key ### Description Get or set the Resend API key globally. This can be set as a static string or a Proc for dynamic loading at request time. ### Method Accessor (getter and setter) ### Parameters #### Setter - **api_key** (String | Proc) - Required - The API key for authentication or a Proc to dynamically retrieve it. #### Getter No parameters. ### Example ```ruby require "resend" # Static API key Resend.api_key = "re_123456" # Dynamic API key from environment Resend.api_key = -> { ENV["RESEND_API_KEY"] } # Dynamic API key from application context Resend.api_key = -> { Current.user.resend_api_key } puts Resend.api_key ``` ``` -------------------------------- ### Lazy Load API Key with Proc Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Use a Proc to dynamically load the API key at request time, supporting environment variables or custom logic. ```ruby require "resend" # With environment variable Resend.api_key = -> { ENV["RESEND_API_KEY"] } # With application context (Rails) Resend.api_key = -> { Current.user.resend_api_key } # Custom logic Resend.api_key = -> { if Rails.env.production? ENV["PROD_API_KEY"] else ENV["DEV_API_KEY"] end } ``` -------------------------------- ### Get Specific Automation Run Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Use this method to retrieve details of a single automation run. Requires both the automation ID and the run ID. ```ruby response = Resend::Automations::Runs.get("auto_123", "run_456") ``` -------------------------------- ### Get a Single Attachment from a Received Email (Ruby) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Use this method to retrieve a specific attachment from a received email. Requires the attachment ID and the email ID. ```ruby response = Resend::Emails::Receiving::Attachments.get( id: "2a0c9ce0-3112-4728-976e-47ddcd16a318", email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" ) ``` -------------------------------- ### Get a Specific Email Attachment Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Retrieve a single attachment from a sent email using its ID and the email's ID. Requires both `:id` and `:email_id` parameters. ```ruby response = Resend::Emails::Attachments.get( id: "2a0c9ce0-3112-4728-976e-47ddcd16a318", email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" ) ``` -------------------------------- ### Configure API Key (Static) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/README.md Set your Resend API key directly. This is suitable for static configurations where the key is known at initialization. ```ruby # Static Resend.api_key = "re..." ``` -------------------------------- ### Create a New API Key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Use this method to generate a new API key. The `:name` parameter is required for configuration. ```ruby response = Resend::ApiKeys.create({ name: "Production API Key" }) api_token = response[:token] ``` -------------------------------- ### Resend.configure Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Configure the Resend SDK using a block. The block receives the configuration object itself as an argument. ```APIDOC ## Resend.configure ### Description Configure the Resend SDK using a block. The block receives the configuration object itself as an argument. ### Method `configure` (or alias `config`) ### Parameters #### Block Parameter - **config** (Block) - Optional - A block that receives the configuration object (`self`) for setting options like `api_key`. ### Return Type Boolean (always true) ### Example ```ruby require "resend" Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end # or use the alias Resend.config do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` ``` -------------------------------- ### List Logs with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Fetches a paginated list of logs. Optional parameters include `:limit`, `:after`, and `:before` for controlling the results. ```ruby response = Resend::Logs.list() ``` -------------------------------- ### create(params) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Creates a new contact with the provided details. Requires an email address and optionally accepts first name, last name, and properties. ```APIDOC ## create(params) ### Description Creates a new contact with the provided details. Requires an email address and optionally accepts first name, last name, and properties. ### Method ```ruby def create(params) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Contact data: `:email` (required), `:first_name`, `:last_name`, `:properties`, `:audience_id` (deprecated, use segment_id) ### Request Example ```ruby response = Resend::Contacts.create({ email: "steve@apple.com", first_name: "Steve", last_name: "Jobs" }) contact_id = response[:id] ``` ### Response #### Success Response - **id** (string) - The ID of the created contact. ``` -------------------------------- ### API Key Parameters for Resend Ruby SDK Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/types.md Outlines the parameters for managing API keys in the Resend Ruby SDK. An API key name is required, and permissions can be optionally specified. ```ruby { name: String, # API key name (required) permissions: Array[String], # Permission scopes (optional) } ``` -------------------------------- ### Handle Invalid Request Errors in Ruby Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/errors.md Catch `Resend::Error::InvalidRequestError` to handle issues like malformed requests or validation errors. This example shows how to rescue this specific error and print its message. ```ruby begin Resend::Emails.send({ from: "invalid-email", # Invalid email format to: ["user@example.com"] }) rescue Resend::Error::InvalidRequestError => e puts "Validation error: #{e.message}" end ``` -------------------------------- ### Resend::Client.new Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Create a new Resend client instance with a specific API key for making authenticated API calls. ```APIDOC ## Resend::Client.new ### Description Create a new Resend client instance with a specific API key for making authenticated API calls. ### Method `initialize` ### Parameters #### Path Parameters - **api_key** (String) - Required - The API key for authentication. ### Return Type `Resend::Client` instance ### Throws `ArgumentError` if `api_key` is not a String. ### Example ```ruby client = Resend::Client.new("re_123456") # Client includes Resend::Emails module response = client.send({ from: "sender@example.com", to: ["recipient@example.com"], subject: "Hello", html: "

Hi

" }) ``` ``` -------------------------------- ### Create a New Topic Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Use this method to create a new email preference topic. Requires a hash containing the topic's name. ```ruby response = Resend::Topics.create({ name: "Marketing Updates" }) ``` -------------------------------- ### Resend::Error Base Class Example Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/errors.md Demonstrates how to rescue the base Resend::Error and access its attributes like message, code, and headers. This is useful for general error handling of any Resend API call. ```ruby begin Resend::Emails.send({}) rescue Resend::Error => e puts "Error: #{e.message}" puts "Code: #{e.code}" puts "Headers: #{e.headers}" end ``` -------------------------------- ### Resend Ruby Contact Property Parameters Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/types.md Parameters for Resend::ContactProperties operations like create, update, get, and remove. Requires a key and type, with optional fallback value and ID for specific operations. ```ruby { key: String, # Property key name (required, max 50 chars, alphanumeric + underscore) type: String, # 'string' or 'number' (required) fallback_value: String | Integer, # Default value when not set (optional, must match type) id: String, # Property ID (used with get/update/remove) } ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Creates a new segment for audience targeting. Requires a hash containing at least the segment's name. ```APIDOC ## create(params) ### Description Creates a new segment for audience targeting. Requires a hash containing at least the segment's name. ### Method ```ruby def create(params) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Segment data: `:name` (required) ### Request Example ```ruby response = Resend::Segments.create({ name: "Active Users" }) ``` ### Response #### Success Response - **id** (String) - The ID of the created segment. #### Response Example (Resend::Response object containing segment data) ``` -------------------------------- ### Rails Integration with ActionMailer Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md The Resend Ruby SDK seamlessly integrates with Rails ActionMailer. This example shows how to configure ActionMailer to use Resend as the delivery method and send emails using standard Rails mailers. ```APIDOC ## Rails Integration The SDK integrates with Rails ActionMailer: ```ruby # config/environments/production.rb config.action_mailer.delivery_method = :resend # Then use Rails mailers normally UserMailer.with(user: user).welcome_email.deliver_now! ``` All ActionMailer headers, attachments, and features are supported. ``` -------------------------------- ### Access Client Instance API Key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Shows how to access the API key associated with a specific Resend client instance using the `api_key` reader method. ```Ruby client = Resend::Client.new("re_123456") puts client.api_key ``` -------------------------------- ### Create an Automation Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Use this method to create a new automated email workflow. It requires a name, trigger event, and a list of actions. ```ruby response = Resend::Automations.create({ name: "Welcome Series", trigger: { event: "user.signed_up" }, actions: [...] }) ``` -------------------------------- ### Handle Argument Errors in Ruby Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/errors.md Catch `ArgumentError` for issues related to missing or invalid parameters passed to SDK methods. This example demonstrates rescuing `ArgumentError` when calling `Resend::Contacts.get` without required parameters. ```ruby begin Resend::Contacts.get({}) # Missing id or email rescue ArgumentError => e puts "Invalid arguments: #{e.message}" end ``` -------------------------------- ### Handle Rate Limit Exceeded Errors with Retry in Ruby Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/errors.md Implement retry logic for `Resend::Error::RateLimitExceededError` to automatically handle rate limiting. The example includes a maximum retry count and uses `e.retry_after` to determine the sleep duration. ```ruby max_retries = 3 retries = 0 begin Resend::Emails.send(params) rescue Resend::Error::RateLimitExceededError => e if retries < max_retries && e.retry_after sleep(e.retry_after) retries += 1 retry else raise end end ``` -------------------------------- ### Set Dynamic API Key with Proc Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md Configure the Resend API key dynamically using a Proc, allowing it to be fetched from an environment variable at runtime. ```ruby Resend.api_key = -> { ENV["RESEND_API_KEY"] } ``` -------------------------------- ### Create a New Broadcast (Draft) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Use this to create a new broadcast as a draft. Set `send: true` to send immediately or use `scheduled_at` for scheduled delivery. `:audience_id` is deprecated. ```ruby response = Resend::Broadcasts.create({ segment_id: "seg_123", from: "sender@example.com", to: "[email]", subject: "Broadcast Title", html: "

Broadcast content

" }) ``` ```ruby # Send immediately response = Resend::Broadcasts.create({ segment_id: "seg_123", from: "sender@example.com", to: "[email]", subject: "Broadcast Title", html: "

Broadcast content

", send: true }) ``` -------------------------------- ### Create a New Webhook Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Creates a new webhook subscription. Requires an `:endpoint` URL and a list of `:events` to subscribe to. The response includes the webhook's ID and signing secret. ```ruby response = Resend::Webhooks.create({ endpoint: "https://webhook.example.com/handler", events: ["email.sent", "email.delivered", "email.bounced"] }) webhook_secret = response[:signing_secret] ``` -------------------------------- ### Build Paginated API Path Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Constructs an API path with pagination parameters like limit, after, and before. Useful for fetching data in chunks. ```ruby path = Resend::PaginationHelper.build_paginated_path("contacts", { limit: 10, after: "cursor_123" }) # => "contacts?limit=10&after=cursor_123" ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Lists email preference topics with optional pagination parameters. ```APIDOC ## list ### Description Lists email preference topics with pagination. ### Method Ruby Method ### Signature ```ruby def list(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Optional - Pagination: `:limit`, `:after`, `:before` ### Request Example ```ruby response = Resend::Topics.list() ``` ### Response #### Success Response - **paginated list** (Resend::Response) - A paginated list of topics ### Response Example ```json { "data": [ { "id": "topic_abc123", "name": "Marketing Updates" } ], "has_more": true } ``` ``` -------------------------------- ### Create a New Domain Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Use this method to create a new sending domain. Requires a hash containing the domain name. ```ruby response = Resend::Domains.create({ domain: "mail.example.com" }) ``` -------------------------------- ### Create a New Contact Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Use this method to add a new contact to your audience. Ensure you provide at least the email address. ```Ruby response = Resend::Contacts.create({ email: "steve@apple.com", first_name: "Steve", last_name: "Jobs" }) contact_id = response[:id] ``` -------------------------------- ### Resend::Response#initialize Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Initializes a new Response object with response data and headers. This object allows for hash-like access to the data and provides access to the response headers. ```APIDOC ## Resend::Response#initialize ### Description Initializes a new Response object with response data and headers. This object allows for hash-like access to the data and provides access to the response headers. ### Signature ```ruby def initialize(data, headers) ``` ### Parameters #### Parameters - **data** (Hash) - Required - The response data - **headers** (Hash) - Optional - The response headers ### Return Type `Resend::Response` instance ### Notes - Response object is Enumerable and supports hash-like access - Maintains backwards compatibility with code expecting Hash responses - Provides access to HTTP headers via the `#headers` method ### Example ```ruby response = Resend::Response.new({id: "123", from: "sender@example.com"}, {"x-ratelimit-remaining" => "50"}) # Hash-like access response[:id] response["from"] response.keys response.values # Header access response.headers["x-ratelimit-remaining"] ``` ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Lists sending domains with optional pagination parameters. ```APIDOC ## list(params = {}) ### Description Lists sending domains with pagination. ### Method ```ruby def list(params = {}) ``` ### Parameters #### Query Parameters - **params** (Hash) - Optional - Pagination: `:limit`, `:after`, `:before` ### Request Example ```ruby response = Resend::Domains.list() ``` ### Response #### Success Response - **domains** (Resend::Response) - paginated list ``` -------------------------------- ### List API Keys Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieve a paginated list of your existing API keys. Optional parameters can be used for pagination. ```ruby response = Resend::ApiKeys.list() ``` -------------------------------- ### List Automations Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Retrieves a paginated list of all your automations. Optional parameters can be provided for controlling the pagination. ```ruby response = Resend::Automations.list() ``` -------------------------------- ### List Webhooks with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Retrieves a paginated list of existing webhooks. Supports pagination parameters like `:limit`, `:after`, and `:before`. ```ruby response = Resend::Webhooks.list(limit: 20) ``` -------------------------------- ### Create a New Email Template with Resend Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Use the `Resend::Templates.create` method to define and create a new email template. Requires template name, subject, and HTML or text content. ```ruby response = Resend::Templates.create({ name: "Welcome Email", subject: "Welcome {{name}}", html: "

Hi {{name}}

" }) ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Lists all segments with optional pagination parameters. ```APIDOC ## list(params = {}) ### Description Lists all segments with optional pagination parameters. ### Method ```ruby def list(params = {}) ``` ### Parameters #### Query Parameters - **params** (Hash) - Optional - Pagination options: `:limit`, `:after`, `:before` ### Request Example ```ruby response = Resend::Segments.list() ``` ### Response #### Success Response - (paginated list) #### Response Example (Resend::Response object containing a paginated list of segments) ``` -------------------------------- ### Create Resend Client with Specific API Key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Instantiate a Resend client with a unique API key for specific operations. This client instance will use its own key, overriding the global `Resend.api_key`. ```ruby client = Resend::Client.new("re_client_specific_api_key") # Use client methods (same as module methods) response = client.send({ from: "sender@example.com", to: ["recipient@example.com"], subject: "Hello", html: "

Hi

" }) ``` -------------------------------- ### List Broadcasts with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Use this to retrieve a paginated list of broadcasts. Optional parameters include `:limit`, `:after`, and `:before` for controlling the results. ```ruby response = Resend::Broadcasts.list() ``` -------------------------------- ### Send a Simple Email Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md Use this snippet to send a basic email. Ensure your RESEND_API_KEY environment variable is set. ```ruby require "resend" Resend.api_key = ENV["RESEND_API_KEY"] response = Resend::Emails.send({ from: "onboarding@example.com", to: ["user@example.com"], subject: "Welcome", html: "

Hello!

" }) email_id = response[:id] ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a paginated list of your existing API keys. Supports filtering by limit, after, and before. ```APIDOC ## list(params = {}) ### Description List API keys with pagination. ### Method ```ruby def list(params = {}) ``` ### Parameters #### Query Parameters - **params** (Hash) - Optional - Pagination options: `:limit`, `:after`, `:before` ### Request Example ```ruby response = Resend::ApiKeys.list() ``` ### Response #### Success Response - **data** (array) - A list of API key objects. - **has_more** (boolean) - Indicates if there are more results. #### Response Example ```json { "data": [ { "id": "key_...", "name": "Production API Key", "last_used_at": "2023-10-27T10:00:00Z" } ], "has_more": false } ``` ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Lists all contact properties with support for pagination using limit, after, and before parameters. ```APIDOC ## list ### Description List contact properties with pagination. ### Method Ruby Method ### Parameters #### Path Parameters - **params** (Hash) - Optional - Pagination: `:limit`, `:after`, `:before` ### Request Example ```ruby response = Resend::ContactProperties.list(limit: 10) ``` ### Response #### Success Response - **paginated list** (Resend::Response) ``` -------------------------------- ### Handle Rate Limit Errors Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md Demonstrates how to catch and handle `RateLimitExceededError` by sleeping for the recommended duration and retrying the request. ```ruby begin Resend::Emails.send(params) rescue Resend::Error::RateLimitExceededError => e sleep(e.retry_after) retry end ``` -------------------------------- ### Initialize Resend Response Object Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Creates a new Resend::Response object with response data and headers. The object supports hash-like access and provides access to HTTP headers. ```ruby response = Resend::Response.new({id: "123", from: "sender@example.com"}, {"x-ratelimit-remaining" => "50"}) # Hash-like access response[:id] response["from"] response.keys response.values # Header access response.headers["x-ratelimit-remaining"] ``` -------------------------------- ### Verify Domain Ownership Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Initiates the verification process for a domain to confirm ownership. Requires the domain ID. ```ruby response = Resend::Domains.verify("domain_123") ``` -------------------------------- ### Map ActionMailer Headers to Resend Parameters Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Demonstrates how standard ActionMailer headers like 'to', 'from', 'subject', 'cc', 'bcc', 'reply_to', and 'tags' are automatically mapped to Resend email parameters. ```ruby class UserMailer < ApplicationMailer def notification_email @user = params[:user] mail( to: @user.email, from: 'notifications@example.com', subject: 'Important Update', cc: ['manager@example.com'], reply_to: 'support@example.com', tags: ['notification'], headers: { 'X-Priority' => '1' } ) end end ``` -------------------------------- ### List Events with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Retrieves a paginated list of events. Optional parameters for pagination include `:limit`, `:after`, and `:before`. ```ruby response = Resend::Events.list() ``` -------------------------------- ### Pagination Parameters for Resend Ruby SDK Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/types.md Defines parameters for paginating results across all Resend API resources. Supports setting a limit per page and navigating using 'after' or 'before' cursors. ```ruby { limit: Integer, # Results per page (1-100, default: 20) after: String, # Cursor for next page before: String, # Cursor for previous page } ``` -------------------------------- ### Resend::Webhooks.list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Lists existing webhooks with pagination support. ```APIDOC ## GET /webhooks ### Description List webhooks with pagination. ### Method GET ### Endpoint `/webhooks` ### Parameters #### Query Parameters - **limit** (integer) - Optional - The number of webhooks to return per page. - **after** (string) - Optional - The ID of the last webhook in the previous page. - **before** (string) - Optional - The ID of the first webhook in the next page. ### Response #### Success Response (200) - **paginated list** (object) - A list of webhook objects with pagination information ### Request Example ```ruby response = Resend::Webhooks.list() response = Resend::Webhooks.list(limit: 20) ``` ``` -------------------------------- ### Webhook Parameters Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/types.md Parameters for webhook operations including creation, update, and verification. ```APIDOC ## Webhook Operations ### Create/Update Webhook #### Parameters - **endpoint** (String) - Required - Webhook URL - **events** (Array[String]) - Required - Event types to subscribe to - **status** (String) - Optional - 'enabled' or 'disabled' - **webhook_id** (String) - Required for update - Webhook ID ### Verify Webhook #### Parameters - **payload** (String) - Required - Raw webhook body - **headers** (Hash[Symbol, String]) - Required - Webhook headers - **webhook_secret** (String) - Required - Signing secret from creation (starts with 'whsec_') #### Webhook Headers Structure - **svix_id** (String) - Message ID - **svix_timestamp** (String) - Unix timestamp - **svix_signature** (String) - HMAC-SHA256 signature **Used by:** `Resend::Webhooks.create()`, `Resend::Webhooks.update()`, `Resend::Webhooks.verify()` ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Create a new contact import from a CSV file. Supports mapping columns, handling conflicts, and assigning segments and topics. ```APIDOC ## POST /contacts/imports ### Description Create a new contact import from a CSV file. Supports mapping columns, handling conflicts, and assigning segments and topics. ### Method POST ### Endpoint /contacts/imports ### Parameters #### Request Body - **file** (Hash | IO) - Required - CSV content or IO object. - **column_map** (Hash) - Optional - Maps contact fields to CSV columns. - **on_conflict** (String) - Optional - 'upsert' (update existing) or 'skip' (default). - **segments** (Array | String) - Optional - Array of segment IDs or pre-encoded JSON String. - **topics** (Array) - Optional - Array of Hashes with `:id` and `:subscription` fields. ### Request Example ```ruby require "resend" csv_content = "email,first_name,last_name\nsteve@apple.com,Steve,Jobs" response = Resend::Contacts::Imports.create({ file: csv_content, column_map: { "Email" => "email", "First Name" => "first_name" }, on_conflict: "upsert", segments: ["seg_123", "seg_456"] }) import_id = response[:id] ``` ### Response #### Success Response (200) - **id** (String) - The ID of the created import job. ``` -------------------------------- ### Set API Key Directly Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Assign your Resend API key directly to the SDK. Ensure the key is kept secret. ```ruby require "resend" Resend.api_key = "re_your_api_key_here" ``` -------------------------------- ### Webhook Create/Update Parameters Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/types.md Parameters for creating or updating webhooks. 'endpoint' and 'events' are required. 'webhook_id' is required for updates. ```ruby { endpoint: String, # Webhook URL (required) events: Array[String], # Event types to subscribe to (required) status: String, # 'enabled' or 'disabled' (optional) webhook_id: String, # Webhook ID (required for update) } ```