0.0
No commit activity in last 3 years
No release in over 3 years
Provides mail functionality for the Cells gem
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

~> 4.0
~> 2.0
 Project Readme

Cells::Mailer

Provides mail functionality for Cells via the Mail gem.

Installation

Add this line to your application's Gemfile:

gem 'cells-mailer'

And then execute:

$ bundle

Configuration

Global configuration

Cell::Mailer.configure do
  to "nick@trailblazer.to"
  from "timo@schilling.io"
  subject "Nick ruls!"
  mail_options deliver_method: :smtp
end

mail_options will be passed to the Mail gem, for details take a look on the Mail gem.

Context configuration

See next chapter.

Usage

class UserNotificationCell < Cell::ViewModel
  include Cell::Mailer
  property :user_name

  def show
    "Hello #{user_name}"
  end
end

UserNotificationCell.(user).deliver(from: "foo@example.com", to: user.email, subject: "Hello")

Body

Equal to Cells, you can deliver (render) different states of your Cell:

class UserNotificationCell < Cell::ViewModel
  include Cell::Mailer
  property :user_name

  def welcome
    "Hello #{user_name}"
  end
end

UserNotificationCell.(user).deliver(..., method: :welcome)

I don't know why you should use it, but you can also pass in a body as argument.

UserNotificationCell.(user).deliver(..., body: "Hello user")

Instance method arguments

You can use instance methods to receive the value for to, from and subject.

class UserNotificationCell < Cell::ViewModel
  include Cell::Mailer
  property :user_name

  def subject
    "Hello #{user_name}"
  end
end

UserNotificationCell.(user).deliver(..., subject: :subject)

Class level configurations

You can use class level configurations for to, from, subject and mail_options. mail_options are passed to Mail, could be used to configure Mail#delivery_method per Cell class.

class UserNotificationCell < Cell::ViewModel
  include Cell::Mailer

  mailer do
    from "nick@trailblazer.to"
    subject "nick loves good code!"
    mail_options delivery_method: :smtp
    format :html # or :text
  end
end

UserNotificationCell.(user).deliver(to: "timo@schilling.io")

This configurations will be inherited.

Roadmap

  • multipart emails
  • attachments