Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Ruby + Resend Examples

Comprehensive examples for sending emails with Resend using Ruby.

Prerequisites

  • Ruby 3.1+
  • Bundler
  • A Resend account

Installation

# Install dependencies
bundle install

# Copy environment variables
cp .env.example .env

# Add your Resend API key to .env

Examples

Basic Email Sending

ruby examples/basic_send.rb

Batch Sending

ruby examples/batch_send.rb

With Attachments

ruby examples/with_attachments.rb

With CID (Inline) Attachments

ruby examples/with_cid_attachments.rb

Scheduled Sending

ruby examples/scheduled_send.rb

Using Templates

ruby examples/with_template.rb

Prevent Gmail Threading

ruby examples/prevent_threading.rb

Audiences & Contacts

ruby examples/audiences.rb

Domain Management

ruby examples/domains.rb

Inbound Email

ruby examples/inbound.rb

Double Opt-In

# Subscribe (creates contact + sends confirmation)
ruby examples/double_optin/subscribe.rb onboarding@resend.dev "John Doe"

# Webhook handler (confirms subscription on click)
# See sinatra_app/app.rb for web endpoint

Sinatra Application

ruby sinatra_app/app.rb

# Then in another terminal:
curl -X POST http://localhost:4567/send \
  -H "Content-Type: application/json" \
  -d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi!"}'

Rails Application

cd rails_app
bundle install
bin/rails server -p 3000

# Then in another terminal:
curl -X POST http://localhost:3000/send \
  -H "Content-Type: application/json" \
  -d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi from Rails!"}'

Quick Usage

require "resend"

Resend.api_key = "re_xxxxxxxxx"

# Send a basic email
result = Resend::Emails.send({
  from: "Acme <onboarding@resend.dev>",
  to: ["delivered@resend.dev"],
  subject: "Hello",
  html: "<p>Hello World</p>"
})

puts "Email ID: #{result["id"]}"

Project Structure

ruby-resend-examples/
├── examples/
│   ├── basic_send.rb          # Simple email sending
│   ├── batch_send.rb          # Multiple emails at once
│   ├── with_attachments.rb    # Emails with files
│   ├── with_cid_attachments.rb # Inline images
│   ├── scheduled_send.rb      # Future delivery
│   ├── with_template.rb       # Using Resend templates
│   ├── prevent_threading.rb   # Prevent Gmail threading
│   ├── audiences.rb           # Manage contacts
│   ├── domains.rb             # Manage domains
│   └── inbound.rb             # Handle inbound emails
├── sinatra_app/
│   └── app.rb                 # Sinatra web app
├── rails_app/                 # Rails API app
│   ├── app/controllers/
│   ├── config/
│   ├── Gemfile
│   └── README.md
├── Gemfile
├── .env.example
└── README.md

Resources

Contributing

See something that could be improved? We welcome contributions! Open an issue to report a bug or suggest an improvement, or submit a pull request with your changes.

License

MIT