Class: EMaily::Email
- Inherits:
-
Object
- Object
- EMaily::Email
- Defined in:
- lib/emaily/emaily.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#from ⇒ Object
Returns the value of attribute from.
-
#list ⇒ Object
Returns the value of attribute list.
-
#ports ⇒ Object
Returns the value of attribute ports.
-
#serv ⇒ Object
Returns the value of attribute serv.
-
#subject ⇒ Object
Returns the value of attribute subject.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Email
constructor
A new instance of Email.
- #send ⇒ Object
- #send_block(bloc = 1, rest = 0, thread = false, &block) ⇒ Object
- #send_to_random_servers(bloc = 1, rest = 0, thread = false) ⇒ Object
- #send_to_servers(bloc = 1, rest = 0, thread = false) ⇒ Object
- #send_web ⇒ Object
- #send_web_block(bloc = 1, rest = 0, thread = false, &block) ⇒ Object
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_type ⇒ Object
Returns the value of attribute content_type.
59 60 61 |
# File 'lib/emaily/emaily.rb', line 59 def content_type @content_type end |
#from ⇒ Object
Returns the value of attribute from.
59 60 61 |
# File 'lib/emaily/emaily.rb', line 59 def from @from end |
#list ⇒ Object
Returns the value of attribute list.
59 60 61 |
# File 'lib/emaily/emaily.rb', line 59 def list @list end |
#ports ⇒ Object
Returns the value of attribute ports.
59 60 61 |
# File 'lib/emaily/emaily.rb', line 59 def ports @ports end |
#serv ⇒ Object
Returns the value of attribute serv.
59 60 61 |
# File 'lib/emaily/emaily.rb', line 59 def serv @serv end |
#subject ⇒ Object
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
#send ⇒ Object
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_web ⇒ Object
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 |