mailing 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mailing
2
2
 
3
- Tool for sending fast mailings
3
+ Tool for sending fast mailings in one SMTP connection.
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,6 +16,11 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install mailing
18
18
 
19
+ ## Sending speed
20
+
21
+ Default sending speed is low and set to ~ 120 mails per minute.
22
+ You can change that value by setting the delay parameter in sender.
23
+
19
24
  ## Step by step usage
20
25
 
21
26
  require 'mailing'
@@ -32,6 +37,7 @@ Or install it yourself as:
32
37
  # create sender with channel, envelope_from and logger
33
38
  logger = Logger.new('/tmp/mailing.log')
34
39
  sender = Mailing::Sender.new(channel, 'sender@domain.com', logger)
40
+ sender.delay = 0.1 # ~ 600 mails per minute
35
41
 
36
42
  # create mailing with from, subject, body, recipients
37
43
  mailing = Mailing::Mailing.new('from@domain.com', 'Subject', 'Body')
@@ -52,7 +58,9 @@ Or install it yourself as:
52
58
  :port => 25,
53
59
  :domain => 'localhost.localdomain'
54
60
  }
55
- mailing.send_by_smtp(config, 'sender@domain.com')
61
+ # send with config and envelope_from set to sender@domain.com
62
+ # without logging and with 0.2 delay (~ 300 mails per minute)
63
+ mailing.send_by_smtp(config, 'sender@domain.com', nil, 0.2)
56
64
 
57
65
  ## Rails usage
58
66
 
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib'
7
+ test.pattern = 'test/*_test.rb'
8
+ end
9
+
10
+ task :default => 'test'
data/lib/mailing.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require 'mailing/version'
2
+ require 'mailing/delay'
2
3
  require 'mailing/mailing'
3
4
  require 'mailing/sender'
5
+ require 'mailing/base_channel'
4
6
  require 'mailing/smtp_channel'
7
+ require 'mailing/fake_channel'
@@ -0,0 +1,19 @@
1
+ module Mailing
2
+ class BaseChannel
3
+
4
+ attr_accessor :config
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def start
11
+ end
12
+
13
+ def deliver(mail, envelope_from, recipient)
14
+ end
15
+
16
+ def finish
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Mailing
2
+ DELAY = 0.5
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'mailing/base_channel'
2
+
3
+ module Mailing
4
+ class FakeChannel < BaseChannel
5
+ def deliver(mail, envelope_from, recipient)
6
+ "Sent to #{recipient}"
7
+ end
8
+ end
9
+ end
@@ -13,9 +13,9 @@ module Mailing
13
13
  sender.send(self)
14
14
  end
15
15
 
16
- def send_by_smtp(config, envelope_from, logger=nil)
16
+ def send_by_smtp(config, envelope_from, logger=nil, delay=DELAY)
17
17
  channel = SmtpChannel.new(config)
18
- sender = Sender.new(channel, envelope_from, logger)
18
+ sender = Sender.new(channel, envelope_from, logger, delay)
19
19
  send(sender)
20
20
  end
21
21
 
@@ -1,8 +1,10 @@
1
+ require 'mailing/delay'
2
+
1
3
  module Mailing
2
4
  class Sender
3
5
  attr_accessor :channel, :envelope_from, :logger, :delay
4
6
 
5
- def initialize(channel, envelope_from, logger=nil, delay=0.5)
7
+ def initialize(channel, envelope_from, logger=nil, delay=DELAY)
6
8
  @channel = channel
7
9
  @envelope_from = envelope_from
8
10
  @logger = logger
@@ -1,9 +1,9 @@
1
+ require 'mailing/base_channel'
2
+
1
3
  module Mailing
2
- class SmtpChannel
4
+ class SmtpChannel < BaseChannel
3
5
  require 'net/smtp'
4
6
 
5
- attr_accessor :config
6
-
7
7
  # config: hash with smtp configuration
8
8
  # {
9
9
  # :address => "host.domain.com",
@@ -16,7 +16,7 @@ module Mailing
16
16
  # :openssl_verify_mode => 'none'
17
17
  # }
18
18
  def initialize(config)
19
- @config = config
19
+ super
20
20
  @smtp = nil
21
21
  end
22
22
 
@@ -1,3 +1,3 @@
1
1
  module Mailing
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
data/mailing.gemspec CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/mailing/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Piotr Macuk"]
6
6
  gem.email = ["piotr@macuk.pl"]
7
- gem.description = %q{Tool for sending fast mailings}
7
+ gem.description = %q{Tool for sending fast mailings in one SMTP connection}
8
8
  gem.summary = %q{Fast mailings}
9
9
  gem.homepage = "https://github.com/macuk/mailing"
10
10
 
@@ -0,0 +1,20 @@
1
+ require 'minitest/autorun'
2
+ require 'mailing/base_channel'
3
+
4
+ class BaseChannelTest < MiniTest::Unit::TestCase
5
+ def setup
6
+ @channel = Mailing::BaseChannel.new('config')
7
+ end
8
+
9
+ def test_config
10
+ assert_equal 'config', @channel.config
11
+ @channel.config = 'test'
12
+ assert_equal 'test', @channel.config
13
+ end
14
+
15
+ def test_methods
16
+ assert_nil @channel.start
17
+ assert_nil @channel.deliver('mail', 'envelope_from', 'recipient')
18
+ assert_nil @channel.finish
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ require 'minitest/autorun'
2
+ require 'mailing/fake_channel'
3
+
4
+ class FakeChannelTest < MiniTest::Unit::TestCase
5
+ def setup
6
+ @channel = Mailing::FakeChannel.new('config')
7
+ end
8
+
9
+ def test_deliver
10
+ assert_equal 'Sent to recipient', @channel.deliver('mail', 'envelope_from', 'recipient')
11
+ end
12
+ end
@@ -0,0 +1,55 @@
1
+ require 'minitest/autorun'
2
+ require 'mailing'
3
+ require 'stringio'
4
+ require 'logger'
5
+ require 'benchmark'
6
+
7
+ class IntegrationTest < MiniTest::Unit::TestCase
8
+ def test_1
9
+ # create channel
10
+ config = {
11
+ :address => 'localhost',
12
+ :port => 25,
13
+ :domain => 'localhost.localdomain'
14
+ }
15
+ channel = Mailing::SmtpChannel.new(config)
16
+
17
+ # create sender with channel, envelope_from and logger
18
+ log = StringIO.new
19
+ logger = Logger.new(log)
20
+ sender = Mailing::Sender.new(channel, 'sender@domain.com', logger)
21
+ sender.delay = 0.1 # ~ 600 mails per minute
22
+
23
+ # create mailing with from, subject, body, recipients
24
+ mailing = Mailing::Mailing.new('from@domain.com', 'Subject', 'Body')
25
+ mailing.recipients = %w(john@domain.com paul@domain.com peter@domain.com)
26
+
27
+ # send mailing
28
+ t = Benchmark.realtime { mailing.send(sender) }
29
+ assert t > 0.3
30
+ assert t < 0.4
31
+
32
+ slog = log.string
33
+ assert_match /from@domain.com/, slog
34
+ assert_match /Subject/, slog
35
+ assert_match /Body/, slog
36
+ mailing.recipients.each { |r| assert_match %r(r), slog }
37
+ end
38
+
39
+ def test_2
40
+ mailing = Mailing::Mailing.new('from@domain.com', 'Subject', 'Body')
41
+ mailing.recipients = %w(john@domain.com paul@domain.com peter@domain.com)
42
+ config = {
43
+ :address => 'localhost',
44
+ :port => 25,
45
+ :domain => 'localhost.localdomain'
46
+ }
47
+ # send with config and envelope_from set to sender@domain.com
48
+ # without logging and with 0.2 delay (~ 300 mails per minute)
49
+ t = Benchmark.realtime do
50
+ mailing.send_by_smtp(config, 'sender@domain.com', nil, 0.2)
51
+ end
52
+ assert t > 0.6
53
+ assert t < 0.7
54
+ end
55
+ end
data/test/sender_test.rb CHANGED
@@ -50,4 +50,18 @@ class SenderTest < MiniTest::Unit::TestCase
50
50
  @mailing.verify
51
51
  @channel.verify
52
52
  end
53
+
54
+ def test_delay
55
+ require 'benchmark'
56
+ @mailing.expect(:recipients, (1..5).to_a)
57
+ @mail.expect(:'to=', nil, [Fixnum])
58
+ @sender.delay = 0.1
59
+ t = Benchmark.realtime { @sender.send(@mailing) }
60
+ assert t > 0.5
61
+ assert t < 0.6
62
+ @sender.delay = 0.2
63
+ t = Benchmark.realtime { @sender.send(@mailing) }
64
+ assert t > 1.0
65
+ assert t < 1.1
66
+ end
53
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.2.5
30
- description: Tool for sending fast mailings
30
+ description: Tool for sending fast mailings in one SMTP connection
31
31
  email:
32
32
  - piotr@macuk.pl
33
33
  executables: []
@@ -40,11 +40,17 @@ files:
40
40
  - README.md
41
41
  - Rakefile
42
42
  - lib/mailing.rb
43
+ - lib/mailing/base_channel.rb
44
+ - lib/mailing/delay.rb
45
+ - lib/mailing/fake_channel.rb
43
46
  - lib/mailing/mailing.rb
44
47
  - lib/mailing/sender.rb
45
48
  - lib/mailing/smtp_channel.rb
46
49
  - lib/mailing/version.rb
47
50
  - mailing.gemspec
51
+ - test/base_channel_test.rb
52
+ - test/fake_channel_test.rb
53
+ - test/integration_test.rb
48
54
  - test/mailing_test.rb
49
55
  - test/sender_test.rb
50
56
  homepage: https://github.com/macuk/mailing
@@ -72,5 +78,8 @@ signing_key:
72
78
  specification_version: 3
73
79
  summary: Fast mailings
74
80
  test_files:
81
+ - test/base_channel_test.rb
82
+ - test/fake_channel_test.rb
83
+ - test/integration_test.rb
75
84
  - test/mailing_test.rb
76
85
  - test/sender_test.rb