Kiss A simpler, smarter web application framework for Ruby

Kiss::Mailer Subclass of Object

Description

@options :server, :port, :domain, :account, :password, :auth - for SMTP login :from/to - used by SMTP to send message (ignored by sendmail) :message - message headers/body text :template - name of email template to use to create message :data/vars - values to inject into email template :sendmail_path - filesystem path to sendmail executable

Attributes

controllerwritable

Not documented

Public Class Methods

new(options = {}) source

Creates new email message object.

    # File lib/kiss/mailer.rb, line 24
    def initialize(options = {})
      @options = {}
      @data = {}
      
      merge_options(options) if options
    end
    

Public Instance Methods

merge_options(options = {}) source

Not documented

    # File lib/kiss/mailer.rb, line 17
    def merge_options(options = {})
      @options.merge!(options)
      @controller = options[:controller] || @controller
      @data = options[:data] || @data
    end
    
prepare_email_message(options = nil) source

Renders email template to string, unless message option is already set to a string value.

    # File lib/kiss/mailer.rb, line 33
    def prepare_email_message(options = nil)
      merge_options(options) if options
    
      unless @options[:message].is_a?(String)
        if template_name = @options[:template]
          @template_dir = controller.email_template_dir
          raise 'email_template_dir path not set' unless @template_dir
      
          data = vars = @options[:data] || @options[:vars]
      
          path = "#{@template_dir}/#{template_name}"
          @options[:message] = erubis(path,binding)
        else
          raise 'email message not defined'
        end
      end
    
      return @options[:message]
    end
    
send(options = nil) source

Attempts to send message using SMTP, unless :engine option is set to :sendmail.

    # File lib/kiss/mailer.rb, line 55
    def send(options = nil)
      merge_options(options) if options
      
      if @options[:engine] == :sendmail
        return sendmail
      else
        return send_smtp
      end
    end
    
send_smtp(options = nil) source

Attempts to send message using Net::SMTP.

    # File lib/kiss/mailer.rb, line 79
    def send_smtp(options = nil)
      merge_options(options) if options
      
      prepare_email_message(options)
    
      require 'net/smtp' unless defined?(Net::SMTP)
      # begin
        Net::SMTP.start(
          @options[:server] || 'localhost',
          @options[:port] || 25,
          @options[:domain] || nil,
          @options[:account] || @options[:username] || nil,
          @options[:password] || nil,
          @options[:auth] || :plain
        ) do |smtp|
                smtp.sendmail(@options[:message], @options[:from], @options[:to])
        end
      # rescue
      # end
    end
    
sendmail(options = nil) source

Attempts to send message using /usr/sbin/sendmail. NOTE: sendmail ignores :from and :to options, using From and To headers from the message

    # File lib/kiss/mailer.rb, line 68
    def sendmail(options = nil)
      merge_options(options) if options
      
      prepare_email_message(options)
    
      IO.popen(@options[:sendmail_path] || "/usr/sbin/sendmail -t","w") do |pipe|
        pipe.puts(@options[:message])
      end
    end
    

Disabled; run with $DEBUG to generate this.