Class: MailQueue::Beanstalk

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Beanstalk



6
7
8
9
10
11
12
13
# File 'lib/mail_queue.rb', line 6

def initialize(options = {})
  self.settings = {
    :pri => 65536,
    :delay => 0,
    :ttr => 120,
    :tube => 'email.send'
  }.merge!(options)
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



15
16
17
# File 'lib/mail_queue.rb', line 15

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



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
44
# File 'lib/mail_queue.rb', line 18

def deliver!(mail)
  # render mail and push onto queue
  envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
  if envelope_from.blank?
    raise ArgumentError.new('A sender (Return-Path, Sender or From) is required to send a message') 
  end
  
  destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
  if destinations.blank?
    raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message') 
  end

  message ||= mail.encoded if mail.respond_to?(:encoded)
  if message.blank?
    raise ArgumentError.new('Encoded content is required to send a message')
  end

  envelope = {
    :from => envelope_from,
    :destinations => destinations,
    :message => message
  }
  
  Stalker.enqueue(settings[:tube], envelope, settings)

  self
end