fhwang.net

RhizMail 0.1.1

I’ve just released the newest version of RhizMail, the email library we use at Rhizome. Most of the changes are minor, but one bigger change is making it easier to parameterize a child of SimpleTemplateMessage.

For example, You can still create a SimpleTemplateMessage directly:

msg = RhizMail::SimpleTemplateMessage.new(
  :to_address => 'john.doe@email.com',
  :from_address => 'webmaster@website.com',
  :template_file => '/Users/francis/Desktop/template.txt'
)
msg.substitute( 'email', 'john.doe@email.com' )
msg.substitute( 'password', 'p4ssw0rd' )
msg.deliver

But you can also create a child, parameterizing it with class methods:

class IntroEmail < RhizMail::SimpleTemplateMessage
  from_address 'webmaster@website.com'
  template     '/Users/francis/Desktop/template.txt'
  substitute   'email', Proc.new { |msg| msg.user.email }
  substitute   'password', Proc.new { |msg| msg.user.password }

  attr_reader :user

  def initialize( user )
    @user = user
    super( :to_address => user.email )
  end
end

User = Struct.new( :email, :password )

u = User.new( 'john.doe@email.com', 'p4ssw0rd' )
email = IntroEmail.new u
blog comments powered by Disqus
Tagged: ruby

« Previous post

Next post »