ShallmentMo / resend-ruby

Resend's Ruby SDK

Home Page:https://resend.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

# /app/initializers/mailer.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"]}

About

Resend's Ruby SDK

https://resend.com


Languages

Language:Ruby 98.8%Language:Dockerfile 0.7%Language:Shell 0.6%