action_mailer-logged_smtp_delivery 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +44 -29
- data/lib/action_mailer/logged_smtp_delivery.rb +17 -27
- metadata +60 -27
- data/test/helper.rb +0 -57
- data/test/logged_smtp_delivery_test.rb +0 -132
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d781ad070664a975fffad82071e7aeedf7ed601
|
4
|
+
data.tar.gz: 761658d0f91601a056abe97f9a3abdddfb51e4b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff13c8e7ee92190f904e893d3a10cca6605a6b9cecff368d71a016289990619b76fa5ddffa18f0909e366a710811e44ed05ff2034f5656d170870b0f82b8ba4b
|
7
|
+
data.tar.gz: 1c9f076ced8d21c1b81183feb3821748acedc71722f8f063631c1eab5ce0cdd13320b294357000c3c849dead56add05484d426f654e535c2f5285e11bff3bd0f
|
data/README.md
CHANGED
@@ -1,33 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
# Logged SMTP Delivery
|
2
|
+
|
3
|
+
```Ruby
|
4
|
+
require 'action_mailer/logged_smtp_delivery'
|
5
|
+
config.action_mailer.logged_smtp_settings = {
|
6
|
+
... normal smtp settings ...,
|
7
|
+
logger: Logger.new, # progress info
|
8
|
+
mail_file_logger: Logger.new # log full encoded mails for storage
|
9
|
+
}
|
10
|
+
|
11
|
+
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
### Detailed log stream with message id prefix. Example:
|
16
|
+
|
17
|
+
```
|
18
|
+
<4e2b38d772949_b81ac212@localhost> stored at example/log/mails/outbound/2011-07-23/7_13462_2.eml
|
19
|
+
<4e2b38d772949_b81ac212@localhost> X-Delivery-Context: [users/1/welcome]
|
20
|
+
<4e2b38d772949_b81ac212@localhost> sender: support@support.localhost
|
21
|
+
<4e2b38d772949_b81ac212@localhost> destinations: support@system.example.com
|
22
|
+
<4e2b38d772949_b81ac212@localhost> done #<Net::SMTP::Response:0x10bbee680 @string="250 2.0.0 Ok: queued as 87BF716D7901\n", @status="250">
|
23
|
+
```
|
24
|
+
|
25
|
+
### Logs an identification header to quickly locate logs for a specific email/entity
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
config.action_mailer.logged_smtp_settings[:log_header] = 'X-Delivery-Context'
|
29
|
+
|
30
|
+
class UsersMailer < ActionMailer::Base
|
31
|
+
|
32
|
+
def welcome(user)
|
33
|
+
headers['X-Delivery-Context'] = "users/#{user.id}/welcome"
|
25
34
|
|
35
|
+
# ...
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
26
39
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
40
|
+
UsersMailer.welcome(user).deliver
|
41
|
+
# ActionMailer::Base.logger ->
|
42
|
+
# <4e2b38d772949_b81ac212@localhost> X-Delivery-Context: [users/1/welcome]
|
43
|
+
```
|
31
44
|
|
32
|
-
|
45
|
+
### Doesn't render BCC recipients
|
46
|
+
|
47
|
+
License: Apache V2
|
33
48
|
|
@@ -1,41 +1,31 @@
|
|
1
1
|
require 'action_mailer'
|
2
|
-
require 'active_support/core_ext/class/attribute'
|
3
2
|
require 'net/smtp'
|
4
3
|
|
5
|
-
#TODO: Add mail file logger
|
6
|
-
|
7
|
-
# A few features:
|
8
|
-
# Hides BCC recipients
|
9
|
-
# Detailed log stream with message id token
|
10
|
-
# Logs an identification header to quickly locate logs for a specific email
|
11
|
-
# Can optionally log the raw email
|
12
|
-
# TLS support
|
13
4
|
module ActionMailer::LoggedSMTPDelivery
|
5
|
+
class Mailer
|
6
|
+
def initialize(settings)
|
7
|
+
@settings = settings
|
8
|
+
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
10
|
+
def deliver!(mail)
|
11
|
+
delivery = SMTPDelivery.new(mail, @settings, @settings.fetch(:logger))
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
if logger = @settings[:mail_file_logger]
|
14
|
+
path = logger.log(mail.encoded)
|
15
|
+
delivery.log "stored at #{path}"
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
path = mail_file_logger.log(mail.encoded)
|
25
|
-
delivery.log "stored at #{path}"
|
18
|
+
delivery.perform
|
26
19
|
end
|
27
|
-
|
28
|
-
delivery.perform
|
29
20
|
end
|
30
21
|
|
31
22
|
class SMTPDelivery
|
23
|
+
attr_reader :mail, :settings, :logger
|
32
24
|
|
33
|
-
|
34
|
-
attr_accessor :logger
|
35
|
-
|
36
|
-
def initialize(mail, settings)
|
25
|
+
def initialize(mail, settings, logger)
|
37
26
|
@mail = mail
|
38
27
|
@settings = settings
|
28
|
+
@logger = logger
|
39
29
|
end
|
40
30
|
|
41
31
|
def perform
|
@@ -76,7 +66,7 @@ module ActionMailer::LoggedSMTPDelivery
|
|
76
66
|
end
|
77
67
|
|
78
68
|
def log_headers
|
79
|
-
log "#{log_header}: [#{mail[log_header]}]"
|
69
|
+
log "#{log_header}: [#{mail[log_header]}]" if log_header
|
80
70
|
end
|
81
71
|
|
82
72
|
def log(message)
|
@@ -90,7 +80,7 @@ module ActionMailer::LoggedSMTPDelivery
|
|
90
80
|
def smtp_adaptor
|
91
81
|
settings[:adaptor] || Net::SMTP
|
92
82
|
end
|
93
|
-
|
94
83
|
end
|
95
|
-
|
96
84
|
end
|
85
|
+
|
86
|
+
ActionMailer::Base.add_delivery_method :logged_smtp, ActionMailer::LoggedSMTPDelivery::Mailer
|
metadata
CHANGED
@@ -1,46 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_mailer-logged_smtp_delivery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Eric Chapweske
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: actionmailer
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.
|
19
|
+
version: 3.2.19
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
26
|
+
version: 3.2.19
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: minitest
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.7.5
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.7.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-rg
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
36
46
|
- !ruby/object:Gem::Version
|
37
47
|
version: '0'
|
38
48
|
type: :development
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bump
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
44
81
|
- !ruby/object:Gem::Version
|
45
82
|
version: '0'
|
46
83
|
description: ActionMailer SMTP delivery strategy with advanced logging and Bcc support
|
@@ -49,34 +86,30 @@ executables: []
|
|
49
86
|
extensions: []
|
50
87
|
extra_rdoc_files: []
|
51
88
|
files:
|
52
|
-
- lib/action_mailer/logged_smtp_delivery.rb
|
53
|
-
- test/helper.rb
|
54
|
-
- test/logged_smtp_delivery_test.rb
|
55
89
|
- README.md
|
56
|
-
|
57
|
-
|
90
|
+
- lib/action_mailer/logged_smtp_delivery.rb
|
91
|
+
homepage: https://github.com/grosser/action_mailer-logged_smtp_delivery
|
92
|
+
licenses:
|
93
|
+
- Apache V2
|
94
|
+
metadata: {}
|
58
95
|
post_install_message:
|
59
96
|
rdoc_options: []
|
60
97
|
require_paths:
|
61
98
|
- lib
|
62
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
100
|
requirements:
|
65
|
-
- -
|
101
|
+
- - ">="
|
66
102
|
- !ruby/object:Gem::Version
|
67
103
|
version: '0'
|
68
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
105
|
requirements:
|
71
|
-
- -
|
106
|
+
- - ">="
|
72
107
|
- !ruby/object:Gem::Version
|
73
108
|
version: '0'
|
74
109
|
requirements: []
|
75
110
|
rubyforge_project:
|
76
|
-
rubygems_version:
|
111
|
+
rubygems_version: 2.2.2
|
77
112
|
signing_key:
|
78
|
-
specification_version:
|
113
|
+
specification_version: 4
|
79
114
|
summary: An ActionMailer delivery strategy
|
80
|
-
test_files:
|
81
|
-
- test/helper.rb
|
82
|
-
- test/logged_smtp_delivery_test.rb
|
115
|
+
test_files: []
|
data/test/helper.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../lib'))) # lib
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
class MemoryLogger
|
6
|
-
|
7
|
-
def log(message)
|
8
|
-
messages << message
|
9
|
-
end
|
10
|
-
|
11
|
-
def messages
|
12
|
-
@messages ||= []
|
13
|
-
end
|
14
|
-
|
15
|
-
def clear
|
16
|
-
messages.clear
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
class FakeSMTP
|
22
|
-
|
23
|
-
attr_reader :address, :port, :credentials
|
24
|
-
|
25
|
-
def self.deliveries
|
26
|
-
@deliveries ||= []
|
27
|
-
end
|
28
|
-
|
29
|
-
def initialize(address, port)
|
30
|
-
@address = address
|
31
|
-
@port = port
|
32
|
-
end
|
33
|
-
|
34
|
-
def start(*credentials)
|
35
|
-
@credentials = credentials
|
36
|
-
@started = true
|
37
|
-
|
38
|
-
yield(self)
|
39
|
-
end
|
40
|
-
|
41
|
-
def send_message(message, from, recipients)
|
42
|
-
self.class.deliveries << [ message, from, recipients ]
|
43
|
-
end
|
44
|
-
|
45
|
-
def enable_starttls_auto
|
46
|
-
@starttls = :auto
|
47
|
-
end
|
48
|
-
|
49
|
-
def starttls_auto?
|
50
|
-
@starttls == :auto
|
51
|
-
end
|
52
|
-
|
53
|
-
def inspect
|
54
|
-
"#<#{self.class} #{@address}:#{@port} started=#{@started}>"
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
require 'action_mailer/logged_smtp_delivery'
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
class LoggedSMTPDeliveryTest < MiniTest::Unit::TestCase
|
6
|
-
|
7
|
-
class TestMailer < ActionMailer::Base
|
8
|
-
include ActionMailer::LoggedSMTPDelivery
|
9
|
-
|
10
|
-
self.mail_file_logger = MemoryLogger.new
|
11
|
-
self.logger = Logger.new(StringIO.new)
|
12
|
-
self.delivery_method = :logged_smtp
|
13
|
-
self.smtp_settings = { :adaptor => FakeSMTP }
|
14
|
-
|
15
|
-
def welcome
|
16
|
-
recipients 'to@example.com'
|
17
|
-
from 'me@example.com'
|
18
|
-
body 'hello'
|
19
|
-
|
20
|
-
# Keep the message simple and consistent between test runs
|
21
|
-
headers['mime-version'] = ''
|
22
|
-
charset nil
|
23
|
-
headers['date'] = ''
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'delivering via actionmailer' do
|
29
|
-
before do
|
30
|
-
TestMailer.mail_file_logger.clear
|
31
|
-
FakeSMTP.deliveries.clear
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'logs the mail to a file when the mail file logger is available' do
|
35
|
-
TestMailer.deliver_welcome
|
36
|
-
assert_equal "From: me@example.com\r\nTo: to@example.com\r\nContent-Type: text/plain\r\n\r\nhello", TestMailer.mail_file_logger.messages.last
|
37
|
-
TestMailer.mail_file_logger.messages.clear
|
38
|
-
|
39
|
-
original_logger = TestMailer.mail_file_logger
|
40
|
-
TestMailer.mail_file_logger = nil
|
41
|
-
assert TestMailer.deliver_welcome
|
42
|
-
TestMailer.mail_file_logger = original_logger
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'delivers the mail' do
|
46
|
-
TestMailer.deliver_welcome
|
47
|
-
delivery = ["From: me@example.com\r\nTo: to@example.com\r\nContent-Type: text/plain\r\n\r\nhello", "me@example.com", ["to@example.com"]]
|
48
|
-
|
49
|
-
assert_equal delivery, FakeSMTP.deliveries.last
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'SMTP Delivery' do
|
55
|
-
before do
|
56
|
-
@settings = { :adaptor => FakeSMTP }
|
57
|
-
@mail = TMail::Mail.new.tap do |mail|
|
58
|
-
mail.message_id = '<12345@example.com>'
|
59
|
-
end
|
60
|
-
@delivery = ActionMailer::LoggedSMTPDelivery::SMTPDelivery.new(@mail, @settings)
|
61
|
-
@log = StringIO.new
|
62
|
-
@delivery.logger = Logger.new(@log)
|
63
|
-
@delivery.logger.formatter = lambda { |severity, datetime, progname, msg| msg }
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'has the sender via the first from address' do
|
67
|
-
@mail.from = [ 'a@example.com', 'b@example.com' ]
|
68
|
-
assert_equal 'a@example.com', @delivery.sender
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'has a list of destination addresses' do
|
72
|
-
@mail.to = 'to@example.com'
|
73
|
-
@mail.cc = 'cc@example.com'
|
74
|
-
@mail.bcc = 'bcc@example.com'
|
75
|
-
|
76
|
-
assert_equal [ 'to@example.com', 'cc@example.com','bcc@example.com' ], @delivery.destinations
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'has an smtp connection' do
|
80
|
-
@delivery.settings[:address] = 'example.com'
|
81
|
-
@delivery.settings[:port] = 26
|
82
|
-
|
83
|
-
smtp = @delivery.smtp
|
84
|
-
assert_equal 26, smtp.port
|
85
|
-
assert_equal 'example.com', smtp.address
|
86
|
-
assert_equal true, smtp.starttls_auto?
|
87
|
-
|
88
|
-
@delivery.settings[:tls] = false
|
89
|
-
assert_equal false, @delivery.smtp.starttls_auto?
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'logs with the mail message id' do
|
93
|
-
@delivery.log 'hello'
|
94
|
-
|
95
|
-
assert_equal '<12345@example.com> hello', @log.string
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'logs headers when the log header is provided' do
|
99
|
-
@delivery.log_headers
|
100
|
-
assert_equal '', @log.string
|
101
|
-
|
102
|
-
@delivery.settings[:log_header] = 'X-Delivery-Context'
|
103
|
-
@delivery.mail['X-Delivery-Context'] = 'hello-33'
|
104
|
-
@delivery.log_headers
|
105
|
-
|
106
|
-
assert_equal '<12345@example.com> X-Delivery-Context: [hello-33]', @log.string
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'sends the mail' do
|
110
|
-
@mail.from = 'me@example.com'
|
111
|
-
@mail.to = 'to@example.com'
|
112
|
-
@mail.cc = 'cc@example.com'
|
113
|
-
@mail.bcc = 'bcc@example.com'
|
114
|
-
@mail.body = 'hello'
|
115
|
-
message = [
|
116
|
-
"From: me@example.com\r\nTo: to@example.com\r\nCc: cc@example.com\r\nMessage-Id: <12345@example.com>\r\n\r\nhello",
|
117
|
-
"me@example.com",
|
118
|
-
["to@example.com", "cc@example.com", "bcc@example.com"]
|
119
|
-
]
|
120
|
-
@delivery.perform
|
121
|
-
|
122
|
-
assert_equal message, FakeSMTP.deliveries.last
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'does not include BCC addresses in the message' do
|
126
|
-
@mail.bcc = 'bcc@example.com'
|
127
|
-
assert_equal false, @delivery.message.include?('bcc@example.com')
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|