Provides mail functionality for Cells via the Mail gem.
Add this line to your application's Gemfile:
gem 'cells-mailer'
And then execute:
$ bundle
Cell::Mailer.configure do
to "[email protected]"
from "[email protected]"
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.
See next chapter.
class UserNotificationCell < Cell::ViewModel
include Cell::Mailer
property :user_name
def show
"Hello #{user_name}"
end
end
UserNotificationCell.(user).deliver(from: "[email protected]", to: user.email, subject: "Hello")
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")
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)
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 "[email protected]"
subject "nick loves good code!"
mail_options delivery_method: :smtp
format :html # or :text
end
end
UserNotificationCell.(user).deliver(to: "[email protected]")
This configurations will be inherited.
- multipart emails
- attachments