Skip to content

Instantly share code, notes, and snippets.

@memoxmrdl
Forked from maxivak/00.md
Created May 18, 2016 12:56
Show Gist options
  • Select an option

  • Save memoxmrdl/8b7dade95f621077cea8e935ced45859 to your computer and use it in GitHub Desktop.

Select an option

Save memoxmrdl/8b7dade95f621077cea8e935ced45859 to your computer and use it in GitHub Desktop.
Sending emails with ActionMailer and Sidekiq

Sending emails with ActionMailer and Sidekiq

Send email asynchroniously using Sidekiq.

ActionMailer

Create your mailer us usual:

# app/mailers/users_mailer.rb

class UsersMailer < ActionMailer::Base

def welcome_email(user_id)
    @user = User.find(user_id)

    mail(   :to      => @user.email,
            :subject => "Welcome"
    ) do |format|
      format.text
      format.html
    end
  end
end

Send email:

user = User.find(1)

mail = UsersMailer.welcome_email(user.id)
#mail.deliver_now
mail.deliver_later

    

Sidekiq

Gemfile:

gem 'sidekiq'

Run Sidekiq

bundle exec sidekiq --environment development -C config/sidekiq.yml 

God + Sidekiq

Use god for monitoring and running sidekiq automatically: https://gist.github.com/maxivak/05847dc7f558d5ef282e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment