mailing 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -2
- data/Rakefile +8 -0
- data/lib/mailing.rb +3 -0
- data/lib/mailing/base_channel.rb +19 -0
- data/lib/mailing/delay.rb +3 -0
- data/lib/mailing/fake_channel.rb +9 -0
- data/lib/mailing/mailing.rb +2 -2
- data/lib/mailing/sender.rb +3 -1
- data/lib/mailing/smtp_channel.rb +4 -4
- data/lib/mailing/version.rb +1 -1
- data/mailing.gemspec +1 -1
- data/test/base_channel_test.rb +20 -0
- data/test/fake_channel_test.rb +12 -0
- data/test/integration_test.rb +55 -0
- data/test/sender_test.rb +14 -0
- metadata +11 -2
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
|
-
|
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
data/lib/mailing.rb
CHANGED
data/lib/mailing/mailing.rb
CHANGED
@@ -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
|
|
data/lib/mailing/sender.rb
CHANGED
@@ -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=
|
7
|
+
def initialize(channel, envelope_from, logger=nil, delay=DELAY)
|
6
8
|
@channel = channel
|
7
9
|
@envelope_from = envelope_from
|
8
10
|
@logger = logger
|
data/lib/mailing/smtp_channel.rb
CHANGED
@@ -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
|
-
|
19
|
+
super
|
20
20
|
@smtp = nil
|
21
21
|
end
|
22
22
|
|
data/lib/mailing/version.rb
CHANGED
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.
|
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
|