Resend Ruby and Rails SDK

License: MIT Build Gem Version

Installation

To install Resend Ruby and Rails SDK, simply execute the following command in a terminal:

Via RubyGems: gem install resend

Via Gemfile: gem 'resend', '~>0.3.0'

Setup

First, you need to get an API key, which is available in the Resend Dashboard.

ruby require "resend" Resend.api_key = ENV["RESEND_API_KEY"]

or

ruby require "resend" Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end

Example

```rb require “resend”

Resend.api_key = ENV[“RESEND_API_KEY”]

params = { “from”: “[email protected]”, “to”: [“[email protected]”, “[email protected]”], “html”: “<h1>Hello World</h1>”, “subject”: “Hey” } r = Resend::Emails.send(params) puts r ```

You can view all the examples in the examples folder

Rails and ActiveMailer support

This gem can be used as an ActionMailer delivery method, add this to your config/environments/environment.rb file and replace with your api key.

ruby config.action_mailer.delivery_method = :resend config.action_mailer.resend_settings = { api_key: 'resend_api_key', }

After that you can deliver_now!, example below:

```ruby #/app/mailers/user_mailer class UserMailer < ApplicationMailer default from: ‘[email protected]’ def welcome_email @user = params[:user] @url = ‘http://example.com/login’ mail(to: [“[email protected]”, “[email protected]”], subject: ‘Hello from Resend’) end end

anywhere in the app

u = User.new name: “derich” mailer = UserMailer.with(user: u).welcome_email mailer.deliver_now! # => from: ‘[email protected]’, to: [“[email protected]”, “[email protected]”] ```

This gem can also be initialized with a Rails initializer file, example below:

ruby # /app/initializers/mailer.rb Resend.configure do |config| config.api_key = 'resend_api_key' end