Send email with merb-mailer in Datamapper model

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 => "no-reply@example.com",
                :to => person.email,
                :subject => "Please activate your account" 
               }   
    end 
  end 
  

Traduction française

Sat, 20 Dec 2008 17:39 Posted in

Tags , , , , ,

If you liked this article you can add me to Twitter

Comment Send email with merb-mailer in Datamapper model


RSS Follow me on Twitter