Comprehensive examples for sending emails with Resend using Ruby.
- Ruby 3.1+
- Bundler
- A Resend account
# Install dependencies
bundle install
# Copy environment variables
cp .env.example .env
# Add your Resend API key to .envruby examples/basic_send.rbruby examples/batch_send.rbruby examples/with_attachments.rbruby examples/with_cid_attachments.rbruby examples/scheduled_send.rbruby examples/with_template.rbruby examples/prevent_threading.rbruby examples/audiences.rbruby examples/domains.rbruby examples/inbound.rb# 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 endpointruby 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!"}'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!"}'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"]}"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
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.
MIT