Module: NotifyOn::EmailSupport

Included in:
Notification
Defined in:
app/models/concerns/notify_on/email_support.rb

Instance Method Summary collapse

Instance Method Details

#email_attachmentsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/concerns/notify_on/email_support.rb', line 38

def email_attachments
  attachments = []
  return attachments unless email_config? && email_config.attachments?
  email_config.attachments.each do |name, renderer|
    next unless trigger.send(renderer.if) if renderer.try(:if?)
    filename = begin
      trigger.send(name)
    rescue => e
      name
    end
    begin
      file = if renderer.is_a?(Symbol)
        trigger.send(renderer)
      else
        trigger.send(renderer.file)
      end
    rescue => e
      raise "Could not create file: #{filename}\n#{e}"
    end
    attachments << { :name => filename, :file => file }
  end
  attachments
end

#email_fromObject



20
21
22
# File 'app/models/concerns/notify_on/email_support.rb', line 20

def email_from
  convert_string(email_from_raw)
end

#email_reply_toObject



24
25
26
# File 'app/models/concerns/notify_on/email_support.rb', line 24

def email_reply_to
  convert_string(email_config.reply_to) if email_config.reply_to?
end

#email_subjectObject



28
29
30
31
# File 'app/models/concerns/notify_on/email_support.rb', line 28

def email_subject
  return email_config.subject if email_config? && email_config.subject?
  description
end

#email_templateObject



15
16
17
18
# File 'app/models/concerns/notify_on/email_support.rb', line 15

def email_template
  return nil unless email_config?
  email_config.template || 'notify'
end

#send_email!Object



4
5
6
7
8
9
10
11
12
13
# File 'app/models/concerns/notify_on/email_support.rb', line 4

def send_email!
  return false unless can_send_email?
  begin
    NotifyOn.configuration.mailer_class.constantize
          .notify(id, email_template, email_attachments)
          .send("deliver_#{email_delivery_timing}")
  rescue Exception => e
    Rails.logger.error("Unable to send notification email: #{e}")
  end
end

#should_save_email_id?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'app/models/concerns/notify_on/email_support.rb', line 33

def should_save_email_id?
  # if we are using postmark and have callbacks for read receipts, we need this to default to true...
  email_config? && email_config.save_id?
end