Project

resend

0.02
There's a lot of open issues
The Ruby and Rails SDK for resend.com
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 0.21.0
 Project Readme

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'

Setup

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

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

or

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

Example

require "resend"

Resend.api_key = ENV["RESEND_API_KEY"]

params = {
  "from": "from@email.io",
  "to": ["to@email.com", "to1@gmail.com"],
  "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.

config.action_mailer.delivery_method = :resend

Create or update your mailer initializer file and replace the placeholder with your Resend API Key.

# /config/initializers/resend.rb
Resend.api_key = "re_123456"

After that you can deliver_now!, example below:

#/app/mailers/user_mailer
class UserMailer < ApplicationMailer
  default from: 'you@yourdomain.io'
  def welcome_email
    @user = params[:user]
    @url  = 'http://example.com/login'
    mail(to: ["example2@mail.com", "example1@mail.com"], 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!
# => {:id=>"b8f94710-0d84-429c-925a-22d3d8f86916", from: 'you@yourdomain.io', to: ["example2@mail.com", "example1@mail.com"]}