Coder Social home page Coder Social logo

resend-ruby's Introduction

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.2.0'

Setup

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

require "resend"
client = Resend::Client.new "re_YOUR_API_KEY"

Example

require "resend"

client = Resend::Client.new "re_YOUR_API_KEY"

params = {
  "from": "[email protected]",
  "to": "[email protected]",
  "html": "<h1>Hello World</h1>",
  "subject": "Hey"
}
r = client.send_email(params)
puts r

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.

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

After that you can deliver_now!, example below:

#/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!
# => {:id=>"b8f94710-0d84-429c-925a-22d3d8f86916", from: '[email protected]', to: ["[email protected]", "[email protected]"]}

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

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

resend-ruby's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.