Prerequisites
To get the most out of this guide, you’ll need to:- Create a SendPost Account
- Ruby on Rails 6.0+
- Ruby 2.7+
- A Sub-Account API Key from your SendPost dashboard
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 yourGemfile:
Ruby
2. Environment Setup
Add toconfig/application.rb or config/environments/production.rb:
Ruby
config/initializers/sendpost.rb:
Ruby
.env or config/application.yml:
3. Create Custom Mail Delivery Method
Createapp/mailers/sendpost_delivery_method.rb:
Ruby
4. Configure ActionMailer
Updateconfig/environments/production.rb:
Ruby
5. Send Your First Email
Using ActionMailer
Create a mailer:app/mailers/user_mailer.rb:
Ruby
app/views/user_mailer/welcome_email.html.erb:
ERB
app/views/user_mailer/welcome_email.text.erb:
ERB
Ruby
6. Common Use Cases
Password Reset Email
Createapp/mailers/user_mailer.rb:
Ruby
app/views/user_mailer/password_reset_email.html.erb:
ERB
Order Confirmation Email
Ruby
app/views/order_mailer/order_confirmation.html.erb:
ERB
7. Using Background Jobs
With Sidekiq
Createapp/jobs/email_job.rb:
Ruby
Ruby
With ActiveJob
Ruby
8. Direct API Usage
Createapp/services/sendpost_service.rb:
Ruby
Ruby
9. Testing
In Development
Add toconfig/environments/development.rb:
Ruby
In Test
Add toconfig/environments/test.rb:
Ruby
Ruby
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