class Knjappserver::Mail
This class represents the queued mails.
Public Class Methods
new(args)
click to toggle source
# File lib/include/class_knjappserver_mailing.rb, line 92 def initialize(args) @args = args raise "No knjappserver-object was given (as :kas)." if !@args[:kas].is_a?(Knjappserver) raise "No :to was given." if !@args[:to] raise "No content was given (:html or :text)." if !@args[:html] and !@args[:text] end
Public Instance Methods
[](key)
click to toggle source
Returns a key from the arguments.
# File lib/include/class_knjappserver_mailing.rb, line 101 def [](key) return @args[key] end
send(args = {})
click to toggle source
Sends the email to the receiver.
# File lib/include/class_knjappserver_mailing.rb, line 106 def send(args = {}) STDOUT.print "Sending mail '#{__id__}'.\n" if @args[:kas].debug if @args[:from] from = @args[:from] elsif @args[:kas].config[:error_report_from] from = @args[:kas].config[:error_report_from] else raise "Dont know where to take the 'from'-paramter from - none given in appserver config or mail-method-arguments?" end if args["proc"] args["proc"].static("Object", "require", "knj/mailobj") mail = args["proc"].new("Knj::Mailobj", @args[:kas].config[:smtp_args]) mail._pm_send_noret("to=", @args[:to]) mail._pm_send_noret("subject=", @args[:subject]) if @args[:subject] mail._pm_send_noret("html=", Knj::Strings.email_str_safe(@args[:html])) if @args[:html] mail._pm_send_noret("text=", Knj::Strings.email_str_safe(@args[:text])) if @args[:text] mail._pm_send_noret("from=", from) mail._pm_send_noret("send") else require "knj/mailobj" mail = Knj::Mailobj.new(@args[:kas].config[:smtp_args]) mail.to = @args[:to] mail.subject = @args[:subject] if @args[:subject] mail.html = Knj::Strings.email_str_safe(@args[:html]) if @args[:html] mail.text = Knj::Strings.email_str_safe(@args[:text]) if @args[:text] mail.from = from mail.send end @args[:status] = :sent STDOUT.print "Sent email #{self.__id__}\n" if @args[:kas].debug return true rescue => e if @args[:kas].debug STDOUT.print "Could not send email.\n" STDOUT.puts e.inspect STDOUT.puts e.backtrace end @args[:errors][e.class.name] = {:count => 0} if !@args[:errors].has_key?(e.class.name) @args[:errors][e.class.name][:count] += 1 raise e if @args[:errors][e.class.name][:count] >= 5 @args[:status] = :error @args[:error] = e return false end