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) ⇒ String

Formats exception context into a plain-text body for admin notification emails.

Parameters:

  • options (Hash)

    the context to format

Options Hash (options):

  • message (String)

    extra message prepended to the context

  • current_user (Object)

    the current user, included when present

  • current_account (Object)

    the current account, included when present

  • exception (Exception)

    the exception; its message and backtrace are included

  • request (ActionDispatch::Request)

    the request; its env is dumped

Returns:

  • (String)

    the formatted context



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/mailers/mailer.rb', line 24

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



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/mailers/mailer.rb', line 56

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



109
110
111
112
113
114
115
116
117
118
119
# File 'app/mailers/mailer.rb', line 109

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



101
102
103
104
105
106
107
# File 'app/mailers/mailer.rb', line 101

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



12
13
14
# File 'app/mailers/mailer.rb', line 12

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

#generic_mailer(options) ⇒ Mail::Message

Generic mailer used to send arbitrary content with optional attachments.

Parameters:

  • options (Hash)

    the mail options

Options Hash (options):

  • to (String, Array<String>)

    recipient address(es)

  • from (Object, String)

    sender; its email is used when it responds to email

  • cc (String, Array<String>, nil)

    cc recipient(s)

  • bcc (String, Array<String>, nil)

    bcc recipient(s)

  • reply_to (String, nil)

    Reply-to header; defaults to the sender's email

  • subject (String)

    the email subject

  • message (String)

    the email body

  • signature (String, nil)

    signature rendered below the body

  • no_verbage (Boolean)

    when truthy, the view skips the standard boilerplate

  • extra_headers (Hash)

    additional mail headers, merged into the message

  • attachments (Array)

    Upload/Item records to attach (see #attach_generic_mailer_files)

  • transmission_method (String, nil)

    e.g. 'fax'; controls how linked publications are attached

Returns:

  • (Mail::Message)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/mailers/mailer.rb', line 84

def generic_mailer(options)
  options[:extra_headers] ||= {}
  sender = options[:from]
  sender_email = sender.try(:email).presence || sender.to_s.presence || 'info@warmlyyours.com'

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

  @document_attachments = attach_generic_mailer_files(options)
  @message = options[:message]
  @signature = 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



149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/mailers/mailer.rb', line 149

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



162
163
164
165
166
# File 'app/mailers/mailer.rb', line 162

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



121
122
123
124
125
126
127
128
129
130
131
# File 'app/mailers/mailer.rb', line 121

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



133
134
135
136
137
138
139
# File 'app/mailers/mailer.rb', line 133

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



141
142
143
144
145
146
147
# File 'app/mailers/mailer.rb', line 141

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