Class: Cowtech::RubyOnRails::Models::EMail
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- Cowtech::RubyOnRails::Models::EMail
- Defined in:
- app/models/cowtech/ruby_on_rails/models/e_mail.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.setup(method = :smtp, config = nil, raise_config_errors = true) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/cowtech/ruby_on_rails/models/e_mail.rb', line 11 def self.setup(method = :smtp, config = nil, raise_config_errors = true) rv = {} if config.is_a?(Hash) then rv = config else begin rv = YAML.load_file(config || (Rails.root + "config/email.yml")) rescue Exception => e raise e if raise_config_errors rv = {} end end ActionMailer::Base.raise_delivery_errors = true ActionMailer::Base.delivery_method = method case method when :fail_test raise ArgumentError when :smtp ActionMailer::Base.smtp_settings = rv[:smtp] end rv end |
Instance Method Details
#generic(args) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/cowtech/ruby_on_rails/models/e_mail.rb', line 42 def generic(args) # Load configuration if !@configuration then config = args.delete(:configuration) if config.is_a?(Hash) then self.setup(config[:method] || args.delete(:method) || :smtp, config) else self.setup(args.delete(:method) || :smtp, args.delete(:configuration_file)) end end # Get arguments and add reply-to args = (args.is_a?(Hash) ? args : args[0]).delete_if { |k,v| v.blank? } args[:reply_to] = args[:from] if !args[:reply_to] # Get body plain_body = args.delete(:body) || args.delete(:plain_body) || args.delete(:text_body) || args.delete(:plain_text) || args.delete(:text) html_body = args.delete(:html_body) || args.delete(:html) mail(args) do |format| if plain_body then format.text { render text: plain_body } end if html_body then format.html { render text: html_body } end end end |