Class: EMaily::Email

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Email

Returns a new instance of Email.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/emaily/emaily.rb', line 38

def initialize(args)
  #setup
  EMaily.log = args[:log] if args[:log]
  @servers = Servers.load
  #variables
  @list = CSV.parse(args[:list])
  @attach = args[:attachment] || []
  @o_from = @from = args[:from]
  @content_type = args[:content_type] || 'text/html; charset=UTF-8;'
  @template = Template.new(args[:template], @content_type)
  @template.bidly = args[:bidly] || false
  @ports = @template.ports
  @template.site = args[:site] if args[:site]
  @subject = @template.subject || args[:subject]
  if args[:servers]
    @serv = []; args[:servers].each {|s| @serv << @servers[s][0][:values] }
    setup_server(@serv[0])
  else
    setup_server(@servers[0][0][:values])
  end
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



59
60
61
# File 'lib/emaily/emaily.rb', line 59

def content_type
  @content_type
end

#fromObject

Returns the value of attribute from.



59
60
61
# File 'lib/emaily/emaily.rb', line 59

def from
  @from
end

#listObject

Returns the value of attribute list.



59
60
61
# File 'lib/emaily/emaily.rb', line 59

def list
  @list
end

#portsObject

Returns the value of attribute ports.



59
60
61
# File 'lib/emaily/emaily.rb', line 59

def ports
  @ports
end

#servObject

Returns the value of attribute serv.



59
60
61
# File 'lib/emaily/emaily.rb', line 59

def serv
  @serv
end

#subjectObject

Returns the value of attribute subject.



59
60
61
# File 'lib/emaily/emaily.rb', line 59

def subject
  @subject
end

Class Method Details

.start(file, &block) ⇒ Object



61
62
63
64
# File 'lib/emaily/emaily.rb', line 61

def self.start(file, &block)
  self.new(file)
  block.call(self) if block_given?
end

Instance Method Details

#sendObject



66
67
68
# File 'lib/emaily/emaily.rb', line 66

def send
  @list.each { |p| connect(p[:email], generate_email(p)) }
end

#send_block(bloc = 1, rest = 0, thread = false, &block) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/emaily/emaily.rb', line 70

def send_block(bloc = 1, rest = 0, thread = false, &block) 
  threads = [] if thread == true
  (@list / bloc).each do |b|
    block.call(self) if block_given?
    if thread        
      threads << Thread.new { b.each { |p| connect p[:email], generate_email(p)}}
    else
      b.each { |p| connect p[:email], generate_email(p) }
    end
  end
  threads.each { |t| t.join }
end

#send_to_random_servers(bloc = 1, rest = 0, thread = false) ⇒ Object



100
101
102
# File 'lib/emaily/emaily.rb', line 100

def send_to_random_servers(bloc = 1, rest = 0, thread = false)
  send_block(bloc, rest, thread) { setup_server(@serv[rand(@serv.size)]) }
end

#send_to_servers(bloc = 1, rest = 0, thread = false) ⇒ Object



104
105
106
107
108
109
# File 'lib/emaily/emaily.rb', line 104

def send_to_servers(bloc = 1, rest = 0, thread = false)
  @v=0; send_block(bloc, rest, thread) do
    setup_server(@serv[@v % @serv.size]);  
    @v += 1
  end
end

#send_webObject



83
84
85
# File 'lib/emaily/emaily.rb', line 83

def send_web
  @list.each { |p| connect_web(@serv[0], p[:email], generate_email(p)) }
end

#send_web_block(bloc = 1, rest = 0, thread = false, &block) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/emaily/emaily.rb', line 87

def send_web_block(bloc = 1, rest = 0, thread = false, &block) 
  threads = [] if thread == true
  (@list / bloc).each do |b|
    block.call(self) if block_given?
    if thread        
      threads << Thread.new { b.each { |p| connect_web(@serv[0], p[:email], generate_email(p))}}
    else
      b.each { |p| connect_web(@serv[0], p[:email], generate_email(p)) }
    end
  end
  threads.each { |t| t.join }
end