Skip to main content

Prerequisites

To get the most out of this guide, you’ll need to:
You can find your API keys in your SendPost Dashboard. Make sure to use your Sub-Account API Key for sending emails.

1. Install Dependencies

Add to your Gemfile:
Ruby
Install:

2. Environment Setup

Add to config/application.rb or config/environments/production.rb:
Ruby
Create or update config/initializers/sendpost.rb:
Ruby
Add to .env or config/application.yml:

3. Create Custom Mail Delivery Method

Create app/mailers/sendpost_delivery_method.rb:
Ruby

4. Configure ActionMailer

Update config/environments/production.rb:
Ruby

5. Send Your First Email

Using ActionMailer

Create a mailer:
Update app/mailers/user_mailer.rb:
Ruby
Create app/views/user_mailer/welcome_email.html.erb:
ERB
Create app/views/user_mailer/welcome_email.text.erb:
ERB
Send the email:
Ruby

6. Common Use Cases

Password Reset Email

Create app/mailers/user_mailer.rb:
Ruby
Create app/views/user_mailer/password_reset_email.html.erb:
ERB

Order Confirmation Email

Ruby
Create app/views/order_mailer/order_confirmation.html.erb:
ERB

7. Using Background Jobs

With Sidekiq

Create app/jobs/email_job.rb:
Ruby
Use it:
Ruby

With ActiveJob

Ruby

8. Direct API Usage

Create app/services/sendpost_service.rb:
Ruby
Use it:
Ruby

9. Testing

In Development

Add to config/environments/development.rb:
Ruby

In Test

Add to config/environments/test.rb:
Ruby
Test mailer:
Ruby
Make sure your sender email domain is verified in your SendPost account before sending emails.

10. Next Steps

Explore more examples and use cases:

Ruby on Rails Documentation

Learn more about Ruby on Rails

SendPost Ruby SDK

View the official SDK on GitHub

ActionMailer Guide

Learn more about ActionMailer

Quickstart Example

View a complete working example on GitHub