snails 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/snails/mailer.rb +34 -6
- data/snails.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06b4aea8ffe430adc00748ea5f48ace43cd79fdf26cebb02da08b31ea88765ac
|
4
|
+
data.tar.gz: 9c856ce125123fe7d3423b362ea948dba6b41038490dea3b0158084ecf2d6b35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddff99a5c53edfb7a897b2c3015cbf883e1db67124df89d5c9cbe7058798cdc644f3954d575b6381ef017c458fa908df40bb14e825bb2ce174810f26844c4e24
|
7
|
+
data.tar.gz: ed3065454f356aaf82e325ae2e46bccafc8c93f39de9ccf99f7079b43bfab913231f4abfd355e437444e7d9d7268532e072c9b8447c782cd09f7079227fa83a1
|
data/lib/snails/mailer.rb
CHANGED
@@ -16,14 +16,26 @@ module Snails
|
|
16
16
|
# class SoftBounce < Bounce; end
|
17
17
|
# class HardBounce < Bounce; end
|
18
18
|
|
19
|
+
def self.backends
|
20
|
+
{
|
21
|
+
'test_backend' => 'Snails::Mailer::TestBackend',
|
22
|
+
'smtp' => 'Snails::Mailer::TuktukBackend',
|
23
|
+
'mailgun' => 'Snails::Mailer::MailgunBackend'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.init_backend(backend_name, opts = {})
|
28
|
+
backend_name = backend_name.presence || 'test_backend'
|
29
|
+
backends[backend_name].constantize.new(opts)
|
30
|
+
end
|
31
|
+
|
19
32
|
def initialize(opts)
|
20
33
|
@from_email = opts[:from] or raise ":from required"
|
21
34
|
@base_subject = opts[:base_subject] || ''
|
22
35
|
@views = opts[:views] || Snails.root.join('lib', 'views')
|
23
36
|
@logfile = opts[:logfile] # || Snails.root.join('log', 'mailer.log')
|
24
37
|
|
25
|
-
|
26
|
-
@backend = self.class.backends[backend_name].new(opts[:backend_options])
|
38
|
+
@backend = self.class.init_backend(opts[:backend_name], opts[:backend_options])
|
27
39
|
end
|
28
40
|
|
29
41
|
def email(name, &block)
|
@@ -77,7 +89,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
77
89
|
|
78
90
|
private
|
79
91
|
|
80
|
-
def render(view_path,
|
92
|
+
def render(view_path, layout_path = nil)
|
81
93
|
view = File.read(File.join(@views, "#{view_path}.erb"))
|
82
94
|
if layout_path
|
83
95
|
layout = File.read(File.join(@views, "#{layout_path}.erb"))
|
@@ -100,7 +112,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
100
112
|
@logger ||= @logfile ? Logger.new(@logfile) : Snails.logger
|
101
113
|
end
|
102
114
|
|
103
|
-
def send_email(from: @from_email, to:, subject:, body: nil, template: nil, layout: nil, html_body: nil, html_template: nil, html_layout: nil, message_id: nil, return_path: nil, list_unsubscribe: nil)
|
115
|
+
def send_email(from: @from_email, to:, subject:, body: nil, template: nil, layout: nil, html_body: nil, html_template: nil, html_layout: nil, message_id: nil, attachments: nil, return_path: nil, list_unsubscribe: nil)
|
104
116
|
raise "No recipient given for mail: #{subject}!" if to.blank?
|
105
117
|
|
106
118
|
message = {
|
@@ -120,6 +132,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
120
132
|
message[:html_body] = html_template ? render(html_template, html_layout) : html_body
|
121
133
|
end
|
122
134
|
|
135
|
+
message[:attachments] = attachments if attachments
|
123
136
|
message[:message_id] = message_id if message_id
|
124
137
|
message[:return_path] = return_path if return_path
|
125
138
|
message[:list_unsubscribe] = list_unsubscribe if list_unsubscribe
|
@@ -140,10 +153,25 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
140
153
|
end
|
141
154
|
end
|
142
155
|
|
143
|
-
class
|
156
|
+
class TestBackend < Backend
|
157
|
+
def initialize(opts = {})
|
158
|
+
end
|
159
|
+
|
160
|
+
def deliver(email, options = {})
|
161
|
+
puts "Deliverying single: #{email[:to]}"
|
162
|
+
end
|
163
|
+
|
164
|
+
def deliver_many(emails, options = {})
|
165
|
+
puts "Deliverying many: #{emails.count}"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
class TuktukBackend < Backend
|
144
170
|
def initialize(config = {})
|
145
171
|
@debug = config[:debug]
|
146
172
|
|
173
|
+
puts "-- #{config.inspect}"
|
174
|
+
|
147
175
|
if key = config.dig(:dkim, :private_key) and File.exist?(key)
|
148
176
|
config[:dkim][:private_key] = IO.read(key)
|
149
177
|
elsif config[:dkim]
|
@@ -170,7 +198,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
170
198
|
end
|
171
199
|
end
|
172
200
|
|
173
|
-
class
|
201
|
+
class MailgunBackend < Backend
|
174
202
|
|
175
203
|
def initialize(api_key:, domain_name:)
|
176
204
|
@key = api_key
|
data/snails.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|