Class: CollinsNotify::EmailAdapter
- Defined in:
- lib/collins_notify/adapter/email.rb
Instance Method Summary collapse
- #configure! ⇒ Object
-
#notify!(message_obj = OpenStruct.new, to = nil) ⇒ Object
Available in template binding sender_address - Address of sender recipient_address - Resolved address of recipient subject - Mail subject message_obj - Depends on call.
Methods inherited from Notifier
adapter_name, adapters, get_adapter, #initialize, mimetypes, register_name, require_config, required_config_keys, requires_config?, #supports_html?, supports_mimetype, #supports_text?
Constructor Details
This class inherits a constructor from CollinsNotify::Notifier
Instance Method Details
#configure! ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/collins_notify/adapter/email.rb', line 9 def configure! mail_cfg = del_meth = mail_cfg.fetch(:delivery_method, :smtp) logger.info "Configuring email delivery method #{del_meth}" logger.debug "Using email config values #{mail_cfg.inspect}" Mail.defaults do delivery_method del_meth, mail_cfg end nil end |
#notify!(message_obj = OpenStruct.new, to = nil) ⇒ Object
Available in template binding
sender_address - Address of sender
recipient_address - Resolved address of recipient
subject - Mail subject
message_obj - Depends on call
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/collins_notify/adapter/email.rb', line 25 def notify! = OpenStruct.new, to = nil sender_address = get_sender_address recipient_address = get_recipient_address , to subject = get_subject = (binding) subject = .subject # Subject may change based on message template (raise CollinsNotify::CollinsNotifyException.new("No subject specified")) if subject.nil? logger.info "From: #{sender_address}, To: #{recipient_address}, Subject: #{subject}" logger.trace "Message body:\n#{}" begin mail = Mail.new logger.debug "Attempting to deliver email message" if config.test? then logger.info "Not delivering email, running in test mode" else logger.info "Delivering email message" mail.deliver! end true rescue Exception => e logger.fatal "Error sending email - #{e}" false end end |