Sha256: 8bf1231fb74f2a2da091d201aa0384ae7cbc06001b7e64dfc2632d24754ff441
Contents?: true
Size: 1.59 KB
Versions: 9
Compression:
Stored size: 1.59 KB
Contents
require "net/smtp" # Admin messages are the messages that are sent out when people are joining # or leaving a mailing list. class AdminMessage < ActiveRecord::Base # The regular expression defining what templates look like. The # templates are the things like {address} that are replaced with # an actual address. TemplateRegex = /\{(\w+)\}/ # Renders the current administration message, filling in the template with # the values with the values in +template_values+. For example, if the # message is: # # Thank you for subscribing to the "{mldesc}" mailing list. # # You might call #render as such: # # adminmsg.render :mldesc => "quick example" # # This would return: # # Thank you for subscribing to the "quick example" mailing list. # # template_values:: # A Hash containing as keys, template keys, and as values, the # values to replace the template keys with. def render template_values template_values.each_key do |k| template_values[k.to_s]=template_values[k] end self.message.gsub(TemplateRegex) do |text| template_values[ text.match(TemplateRegex)[1] ] end end # Sends out an admin message with with the +from+ address in the # envelope "From" string, the +to+ address in the envelope "To" string, # and with with +template_values+ expanded as in +render+.1 def send_mail from, to, template_values Net::SMTP.start("localhost", 25) do |smtp| smtp.send_message render(template_values), from, to end end end
Version data entries
9 entries across 9 versions & 1 rubygems