Class: Mailer

Inherits:
ApplicationMailer show all
Defined in:
app/mailers/mailer.rb

Overview

ActionMailer: mailer.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationMailer

#null_mail

Class Method Details

.format_exception(options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/mailers/mailer.rb', line 13

def self.format_exception(options)
  request_context = +''
  if options[:message]
    request_context << options[:message]
    request_context << "\n-----------------------------------------------\n"
  end
  if options[:current_user]
    request_context << "Current User: #{options[:current_user]}"
    request_context << "\n-----------------------------------------------\n"
  end

  if options[:current_account]
    request_context << "Current Account: #{options[:current_account]}"
    request_context << "\n-----------------------------------------------\n"
  end

  if options[:exception]
    request_context << "Exception: #{options[:exception]}\n\n"
    request_context << "Backtrace:"
    request_context << options[:exception].backtrace.join("\n")
    request_context << "\n-----------------------------------------------\n"
  end

  if options[:request]
    request_context << "\n\nRequest:"
    options[:request].env.each { |k, v| request_context << "#{k} : #{v}\n" }
    request_context << "\n-----------------------------------------------\n"
  end

  request_context
end

Instance Method Details

#admin_notification(subj, message = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/mailers/mailer.rb', line 45

def admin_notification(subj, message = nil)
  if message.nil?
    message = subj
    subj = "An admin notification was sent"
  end
  @message = if message.is_a? Hash
               Mailer.format_exception(message)
             else
               message
             end
  mail(to: ADMINISTRATOR_EMAIL, subject: subj, from: ADMINISTRATOR_EMAIL)
end

#canada_post_manual_void_email(delivery, tracking_numbers) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'app/mailers/mailer.rb', line 106

def canada_post_manual_void_email(delivery, tracking_numbers)
  begin
    delivery.customer.store.id
  rescue StandardError
    1
  end
  sender = 'heatwaveteam@warmlyyours.com'
  @delivery = delivery
  @tracking_numbers = tracking_numbers
  mail(from: sender, to: 'orders@warmlyyours.com', subject: "Delivery was voided in Heatwave but shipments were not cancelled through Canada Post API, see enclosed tracking numbers")
end

#canada_post_manual_void_email_for_mail_activity(mail_activity, tracking_numbers) ⇒ Object



98
99
100
101
102
103
104
# File 'app/mailers/mailer.rb', line 98

def canada_post_manual_void_email_for_mail_activity(mail_activity, tracking_numbers)
  mail_activity.store.id
  sender = 'heatwaveteam@warmlyyours.com'
  @mail_activity = mail_activity
  @tracking_numbers = tracking_numbers
  mail(from: sender, to: 'orders@warmlyyours.com', subject: "Mail Activity was voided in Heatwave but shipments were not cancelled through Canada Post API, see enclosed tracking numbers")
end

#default_url_optionsObject



9
10
11
# File 'app/mailers/mailer.rb', line 9

def default_url_options
  UrlHelper.default_url_options({ host: CRM_HOSTNAME })
end

#generic_mailer(options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/mailers/mailer.rb', line 58

def generic_mailer(options)
  options[:extra_headers] ||= {}
  sender = options[:from]
  sender_email = sender.try(:email) || sender.to_s || "info@warmlyyours.com"
  files_to_attach = options[:attachments] || []
  document_attachments = []
  files_to_attach.each do |a|
    options[:cc] = ACCOUNTS_PAYABLE_EMAIL if a.instance_of?(Upload) && (a.category == "purchase_order")
    if a.instance_of?(Upload) && %w[organization_quote_pdf msrp_quote_pdf].include?(a.category)
      attachments["Quote #{a.resource.reference_number}.pdf"] = a.attachment.data
    elsif a.instance_of?(Upload) && (a.category == "invoice_pdf")
      attachments["Invoice #{a.resource.reference_number}.pdf"] = a.attachment.data
    elsif a.respond_to?(:attachment) && a.attachment.present?
      attachments[a.attachment_name] = a.attachment.data
    elsif a.respond_to?(:legacy_attachment) && a.legacy_attachment.file?
      attachments[a.attachment_name] = a.attachment.data
    elsif a.is_a? Item # Publication
      if (options[:transmission_method] == "fax") || !a.is_available_to_public
        attachments[a.public_file_name] = a.attachment.data
      elsif a.is_available_to_public
        document_attachments << a
      end
    end
  end

  headers["Reply-to"] = options[:reply_to] || sender_email

  @documents_plain = Communication.documents_plain(document_attachments)
  @documents_html = Communication.documents_html(document_attachments)
  @message_plain = options[:message]
  @message_html = Communication.text_to_html(options[:message])
  @signature_plain = options[:signature]
  @signature_html = Communication.signature_to_html(options[:signature])
  @no_verbage = options[:no_verbage]
  options[:extra_headers].each do |k, v|
    headers[k] = v
  end
  mail(to: options[:to], from: sender_email, cc: options[:cc], bcc: options[:bcc], subject: options[:subject])
end

#manual_pickup_required_email(delivery) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/mailers/mailer.rb', line 146

def manual_pickup_required_email(delivery)
  @delivery = delivery
  @contact = delivery.manual_pickup_contact
  warehouse_email = delivery.store&.warehouse_email
  return unless warehouse_email.present? && @contact.present?

  mail(
    from: 'heatwaveteam@warmlyyours.com',
    to: warehouse_email,
    subject: "ACTION REQUIRED: Arrange #{@contact[:name]} pickup for #{delivery.name}"
  )
end

#personal_connect(sender, values = {}) ⇒ Object



159
160
161
162
163
# File 'app/mailers/mailer.rb', line 159

def personal_connect(sender, values = {})
  @values = values
  @no_verbage = true
  mail(from: sender, to: "webenquiries@warmlyyours.com", subject: "A personal connect enquiry was made from #{sender} on: #{Time.current}")
end

#purolator_manual_void_email(delivery, tracking_numbers) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
# File 'app/mailers/mailer.rb', line 118

def purolator_manual_void_email(delivery, tracking_numbers)
  begin
    delivery.customer.store.id
  rescue StandardError
    1
  end
  sender = 'heatwaveteam@warmlyyours.com'
  @delivery = delivery
  @tracking_numbers = tracking_numbers
  mail(from: sender, to: 'orders@warmlyyours.com', subject: "Delivery was voided in Heatwave but shipments were not cancelled through Purolator API, see enclosed tracking numbers")
end

#saia_schedule_pickup_failed_email(email, deliveries, message) ⇒ Object



130
131
132
133
134
135
136
# File 'app/mailers/mailer.rb', line 130

def saia_schedule_pickup_failed_email(email, deliveries, message)
  sender = 'heatwaveteam@warmlyyours.com'
  @carrier = 'Saia'
  @deliveries = deliveries
  @message = message
  mail(from: sender, to: email, subject: "Could not schedule SAIA pickup, you may want to schedule it manually")
end

#schedule_pickup_failed_email(email, carrier, deliveries, message) ⇒ Object



138
139
140
141
142
143
144
# File 'app/mailers/mailer.rb', line 138

def schedule_pickup_failed_email(email, carrier, deliveries, message)
  sender = 'heatwaveteam@warmlyyours.com'
  @carrier = carrier
  @deliveries = deliveries
  @message = message
  mail(from: sender, to: email, subject: "Could not schedule #{carrier} pickup, you may want to schedule it manually")
end