Class: NotifyOn::NotificationMailer

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

Instance Method Summary collapse

Instance Method Details

#notify(notification_id, template = 'notify', files = []) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/mailers/notify_on/notification_mailer.rb', line 6

def notify(notification_id, template = 'notify', files = [])
  @notification = NotifyOn::Notification.find_by_id(notification_id)
  @recipient = @notification.recipient
  @sender = @notification.sender
  @trigger = @notification.trigger
  # Add attachments.
  files.each { |attr| attachments[attr[:name]] = attr[:file] }
  # Save a reference to the message if requested.
  if @notification.should_save_email_id?
    headers['message-id'] = (message_id = SecureRandom.uuid)
    @trigger.update_columns(:message_id => message_id)
  end
  mail :to => @recipient.email,
       :from => @notification.email_from,
       :reply_to => @notification.email_reply_to || @notification.email_from,
       :subject => @notification.email_subject,
       :template_path => 'notifications',
       :template_name => template
end