maildis 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/maildis.rb +4 -8
- data/lib/maildis/dispatcher.rb +10 -6
- data/lib/maildis/validation_utils.rb +5 -2
- data/lib/maildis/version.rb +1 -1
- metadata +7 -1
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/jboursiquot/maildis) [![Dependency
|
5
5
|
Status](https://gemnasium.com/jboursiquot/maildis.png)](https://gemnasium.com/jboursiquot/maildis)
|
6
6
|
|
7
|
-
Maildis is a command line bulk email dispatching tool. It supports HTML and plain text templates and CSVs for recipients
|
7
|
+
Maildis is a command line bulk email dispatching tool. It supports HTML and plain text templates with merge tags and CSVs for specifying recipients. It relies on SMTP information you provide through your own configuration file. Subject, sender, path to CSV and path to the templates are all configurable through YAML.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
data/lib/maildis.rb
CHANGED
@@ -46,17 +46,13 @@ module Maildis
|
|
46
46
|
init_logger options[:verbose]
|
47
47
|
begin
|
48
48
|
config = load_config mailer_path
|
49
|
-
subject = config['mailer']['subject']
|
50
49
|
recipients = load_recipients config['mailer']['recipients']
|
51
|
-
sender = load_sender config['mailer']['sender']
|
52
|
-
templates = load_templates config['mailer']['templates']
|
53
|
-
server = load_server config['smtp']
|
54
50
|
info "Dispatching to #{recipients.size} recipients"
|
55
|
-
result = Dispatcher.dispatch({subject: subject,
|
51
|
+
result = Dispatcher.dispatch({subject: config['mailer']['subject'],
|
56
52
|
recipients: recipients,
|
57
|
-
sender: sender,
|
58
|
-
templates: templates,
|
59
|
-
server:
|
53
|
+
sender: load_sender(config['mailer']['sender']),
|
54
|
+
templates: load_templates(config['mailer']['templates']),
|
55
|
+
server: load_server(config['smtp']),
|
60
56
|
logger: @@logger})
|
61
57
|
info "Dispatch complete with errors" if result[:not_sent].size > 0
|
62
58
|
info "Dispatch complete without errors" if result[:not_sent].size == 0
|
data/lib/maildis/dispatcher.rb
CHANGED
@@ -9,32 +9,36 @@ module Maildis
|
|
9
9
|
|
10
10
|
def dispatch(options = {})
|
11
11
|
result = {sent: [], not_sent: []}
|
12
|
+
init_logger options[:logger]
|
13
|
+
|
12
14
|
options[:recipients].each do |recipient|
|
13
15
|
begin
|
14
|
-
html_body = TemplateRenderer.render(options[:templates][:html], recipient.merge_fields)
|
15
|
-
plain_body = TemplateRenderer.render(options[:templates][:plain], recipient.merge_fields)
|
16
16
|
Pony.mail({
|
17
17
|
to: recipient.to_email,
|
18
18
|
from: options[:sender].to_email,
|
19
19
|
subject: options[:subject],
|
20
|
-
html_body:
|
21
|
-
body:
|
20
|
+
html_body: TemplateRenderer.render(options[:templates][:html], recipient.merge_fields),
|
21
|
+
body: TemplateRenderer.render(options[:templates][:plain], recipient.merge_fields),
|
22
22
|
via: :smtp,
|
23
23
|
via_options: {address: options[:server].host,
|
24
24
|
port: options[:server].port,
|
25
25
|
user_name: options[:server].username,
|
26
26
|
password: options[:server].password}
|
27
27
|
})
|
28
|
-
|
28
|
+
info "Sent: #{recipient.to_email}"
|
29
29
|
result[:sent] << recipient
|
30
30
|
rescue => e
|
31
|
-
|
31
|
+
error "Error: #{recipient.to_email} | #{e.message}"
|
32
32
|
result[:not_sent] << {recipient: recipient, reason: e.message}
|
33
33
|
end
|
34
34
|
end
|
35
35
|
result
|
36
36
|
end
|
37
37
|
|
38
|
+
def init_logger(logger = nil); @@logger ||= logger; end
|
39
|
+
def info(msg); @@logger.info msg if @@logger; end
|
40
|
+
def error(msg); @@logger.error msg if @@logger; end
|
41
|
+
|
38
42
|
end
|
39
43
|
|
40
44
|
end
|
@@ -3,9 +3,12 @@ class ValidationUtils
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
def valid_hostname?(hostname)
|
6
|
-
|
7
|
-
|
6
|
+
if !hostname || hostname.length > 255 || hostname.scan('..').any?
|
7
|
+
return false
|
8
|
+
end
|
9
|
+
|
8
10
|
return true if hostname == 'localhost'
|
11
|
+
|
9
12
|
hostname = hostname[0 ... -1] if hostname.index('.', -1)
|
10
13
|
return hostname.split('.').collect { |i| i.size <= 63 && !(i.rindex('-', 0) || i.index('-', -1) || i.scan(/[^a-z\d-]/i).any?)}.all?
|
11
14
|
end
|
data/lib/maildis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maildis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -253,12 +253,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
253
|
- - ! '>='
|
254
254
|
- !ruby/object:Gem::Version
|
255
255
|
version: '0'
|
256
|
+
segments:
|
257
|
+
- 0
|
258
|
+
hash: 1586982649754055890
|
256
259
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
260
|
none: false
|
258
261
|
requirements:
|
259
262
|
- - ! '>='
|
260
263
|
- !ruby/object:Gem::Version
|
261
264
|
version: '0'
|
265
|
+
segments:
|
266
|
+
- 0
|
267
|
+
hash: 1586982649754055890
|
262
268
|
requirements: []
|
263
269
|
rubyforge_project:
|
264
270
|
rubygems_version: 1.8.24
|