Shiny happy people coding

Coding with smile

Send Email With Merb-mailer in Datamapper Model

| Comments

With Merb-mailer, merb offer a system to send email. But merb is a web framework ORM agnostic. So merb-mailer is like a controller, not a model like in Rails. So the send_mail method is available only in controller. But how use this method in our Datamapper model? It's really simple because Merb use the good way in Ruby and help to use that.

After a short research in code of merb-mailer. I look that the send_mail method is in Mixin. After include this mixin in your class, you can use the send_mail method.

class Member include DataMapper::Resource include Merb::MailerMixin property :id, Serial property :name, String def register // some code send_mail (UserMailer, :register, { :from => "", :to =>, :subject => "Please activate your account" } end end

Traduction fran├žaise