This is a Hertz courier for sending notifications to your users via email throuh ActionMailer.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install hertz-courier-email
Then, run the installer generator:
$ rails g hertz:courier:email:install
You will also need to expose the
hertz_email method in your receiver class:
class User < ActiveRecord::Base include ::Notifiable def hertz_email email end end
#hertz_email returns an empty value (i.e.
nil or an empty
string) at the time the job is executed, the notification will not be delivered.
This allows you to programmatically enable/disable email notifications for a
class User include ::Notifiable def hertz_email email if email_verified? end end
In order to use this courier, add
deliver_by in the notification
class CommentNotification < ::Notification deliver_by :email end
Now, add the
email_subject method in your notification class:
class CommentNotification < ::Notification def email_subject 'You have a new comment!' end end
Finally, you should create a template for every notification you send by email.
CommentNotification you'd create a template at
<p>Hey <%= @notification.receiver.hertz_email %>,</p> <p>you've got a new comment!</p>
As you can see, templates have access to the
@notification instance variable.
Bug reports and pull requests are welcome on GitHub at https://github.com/alessandro1997/hertz-courier-email.
The gem is available as open source under the terms of the MIT License.
- [ ] Store notification delivery in the DB to avoid resending