This creates config/initializers/courrier.rb for configuring email providers and default settings.
Usage
Generate a new email:
bin/rails generate courrier:email Order
classOrderEmail < Courrier::Emaildefsubject = "Here is your order!"deftext<<~TEXT
text body here
TEXTenddefhtml<<~HTML
html body here
HTMLendend# OrderEmail.deliver to: "recipient@railsdesigner.com"
Provider and API key settings can be overridden using environment variables (COURRIER_PROVIDER and COURRIER_API_KEY) for both global configuration and email class defaults.
Custom Attributes
Besides the standard email attributes (from, to, reply_to, etc.), you can pass any additional attributes that will be available in your email templates:
These custom attributes are accessible directly in your email class:
deftext<<~TEXT
#{download_url}
TEXTend
Result Object
When sending an email through Courrier, a Result object is returned that provides information about the delivery attempt. This object offers a simple interface to check the status and access response data.
Available Methods
Method
Return Type
Description
success?
Boolean
Returns true if the API request was successful
response
Net::HTTP::Response
The raw HTTP response from the email provider
data
Hash
Parsed JSON response body from the provider
error
Exception
Contains any error that occurred during delivery
Example
delivery = OrderEmail.deliver(to:"recipient@example.com")
if delivery.success?
puts "Email sent successfully!"
puts "Provider response: #{delivery.data}"else
puts "Failed to send email: #{delivery.error}"end
Providers
Courrier supports these transactional email providers:
⚠️ Some providers still need manual verification of their implementation. If you're using one of these providers, please help verify the implementation by sharing your experience in this GitHub issue. 🙏
More Features
Additional functionality to help with development and testing:
Inbox (Rails only)
You can preview your emails in the inbox:
config.provider = "inbox"# And add to your routes:
mount Courrier::Engine => "/courrier"
If you want to automatically open every email in your default browser:
We found that courrier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.
Package last updated on 13 May 2025
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.