html2mail 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +10 -3
- data/bin/html2mail +67 -25
- data/html2mail.gemspec +4 -1
- data/lib/html2mail/mailer2.rb +9 -15
- data/lib/html2mail/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bb5798551dddb8ccc6a7694dcaaa469a4c6b596
|
4
|
+
data.tar.gz: 2d98c196ae8c42eb2492f45dec4d3b755d9072a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c3aa5fea6cf675fac779141b85d40e271cee6e13c7a92cad508f39291bf4d8c981c7303975438c8ef09a236dd06ab8c4b8eb0cb426b7905059f201d156f060
|
7
|
+
data.tar.gz: ead577fc1155dc7f5d45df472d518e3ec46c38a9603968961d4b37a1116865045c603dc5d640790f0c4efdd1d9b9905de05f3e279c78e5c4cca487c9adae2edd
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# html2mail
|
2
2
|
|
3
|
-
|
3
|
+
Console tool which generates html/eml stuff for your newsletters from html-files (support images in separate files)
|
4
4
|
|
5
5
|
|
6
6
|
## Examples
|
@@ -27,19 +27,26 @@ Save "premailed" HTML files (convert css to inline styles):
|
|
27
27
|
|
28
28
|
Send test emails and use stored config for SMTP server:
|
29
29
|
|
30
|
-
`html2mail send /path/to/newsletters/*.html --to your@domain.com --
|
30
|
+
`html2mail --smtp_address=mail.example.com --smtp_user_name=newsletter@example.com --smtp_password=princess1 send /path/to/newsletters/*.html --to your@domain.com --subj='Test mail'`
|
31
|
+
|
31
32
|
|
32
33
|
Init SMTP config:
|
33
34
|
|
34
35
|
> WARNING: Password stored as plain text in config file `.html2mail.yml` file in $HOME for Linux
|
35
36
|
|
36
|
-
`html2mail --
|
37
|
+
`html2mail --smtp_address=mail.example.com --smtp_user_name=newsletter@example.com --smtp_password=princess1 initconfig`
|
38
|
+
|
37
39
|
|
38
40
|
Send test emails and use stored config for SMTP server:
|
39
41
|
|
40
42
|
`html2mail send /path/to/newsletters/*.html --to your@domain.com`
|
41
43
|
|
42
44
|
|
45
|
+
Send newsletter.html to all adresses from list.txt:
|
46
|
+
|
47
|
+
`html2mail bulksend -l list.txt newsletter.html`
|
48
|
+
|
49
|
+
|
43
50
|
## Based on gems
|
44
51
|
|
45
52
|
* ActionMailer
|
data/bin/html2mail
CHANGED
@@ -6,30 +6,22 @@ require 'gli'
|
|
6
6
|
|
7
7
|
include GLI::App
|
8
8
|
|
9
|
-
|
10
9
|
program_desc 'Convert html file with images to e-mail'
|
10
|
+
version Html2mail::VERSION
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# # $todo_list = Hacer::Todolist.new(global_options[:tasklist])
|
17
|
-
# end
|
18
|
-
|
19
|
-
|
20
|
-
flag [:domain], default_value: nil
|
21
|
-
flag [:user], default_value: nil
|
22
|
-
flag [:password], default_value: nil
|
23
|
-
switch [:starttls], default_value: true
|
12
|
+
flag [:smtp_address], default_value: nil, desc: "SMTP server address"
|
13
|
+
flag [:smtp_user_name], default_value: nil, desc: "SMTP server user name (email address)"
|
14
|
+
flag [:smtp_password], default_value: nil, desc: "SMTP server user password"
|
15
|
+
switch [:smtp_starttls], default_value: true, desc: "Enables SMTP/TLS (STARTTLS)"
|
24
16
|
|
25
17
|
config_file '.html2mail.yml'
|
26
18
|
|
27
19
|
pre do |global, command, options, args|
|
28
20
|
Mailer2.delivery_method = :smtp
|
29
|
-
Mailer2.smtp_settings = {:address => global[:
|
30
|
-
:user_name => global[:
|
31
|
-
:password => global[:
|
32
|
-
:enable_starttls_auto => global[:
|
21
|
+
Mailer2.smtp_settings = {:address => global[:smtp_address],
|
22
|
+
:user_name => global[:smtp_user_name],
|
23
|
+
:password => global[:smtp_password],
|
24
|
+
:enable_starttls_auto => global[:smtp_starttls]}
|
33
25
|
end
|
34
26
|
|
35
27
|
desc 'Sent email from html to given adress'
|
@@ -39,7 +31,6 @@ command :send do |c|
|
|
39
31
|
c.flag [:s, :subj], default_value: nil
|
40
32
|
|
41
33
|
c.action do |global_options, options, args|
|
42
|
-
# STDERR.puts args
|
43
34
|
args.each do |f|
|
44
35
|
STDERR.puts "Start mail processing"
|
45
36
|
|
@@ -59,7 +50,6 @@ command :convert do |c|
|
|
59
50
|
c.flag [:o, :output], default_value: nil
|
60
51
|
|
61
52
|
c.action do |global_options, options, args|
|
62
|
-
# STDERR.puts "Processing: #{args}"
|
63
53
|
args.each do |f|
|
64
54
|
m = Mailer2.mail2 f, options[:to], options[:subj], global_options[:user]
|
65
55
|
|
@@ -74,7 +64,7 @@ command :convert do |c|
|
|
74
64
|
out = File.join(File.dirname(f), File.basename(f, File.extname(f)) + '.eml')
|
75
65
|
end
|
76
66
|
|
77
|
-
STDERR.puts "
|
67
|
+
STDERR.puts "Out: #{out}"
|
78
68
|
# raise "File already exists: #{out}" if File.exists?(out)
|
79
69
|
File.open(out, 'w') { |fw| fw.write(html) }
|
80
70
|
end
|
@@ -95,9 +85,6 @@ command :prepare do |c|
|
|
95
85
|
c.action do |global_options, options, args|
|
96
86
|
STDERR.puts "Processing: #{args.join(', ')}"
|
97
87
|
args.each do |f|
|
98
|
-
# if f.end_with?(options[:premailer_suffix])
|
99
|
-
# STDERR.puts "Skip already premailed html: #{File.basename(f)}"
|
100
|
-
# else
|
101
88
|
html = Premailer.new(f, :warn_level => Premailer::Warnings::SAFE).to_inline_css.html_safe
|
102
89
|
|
103
90
|
if options[:stdout]
|
@@ -108,17 +95,72 @@ command :prepare do |c|
|
|
108
95
|
else
|
109
96
|
premailed_dir = File.join(File.dirname(f), options[:premailer_dir])
|
110
97
|
FileUtils.mkdir_p(premailed_dir)
|
111
|
-
out = File.join(premailed_dir, options[:premailer_prefix] + File.basename(f, File.extname(f)) + options[:premailer_suffix] +File.extname(f))
|
98
|
+
out = File.join(premailed_dir, options[:premailer_prefix] + File.basename(f, File.extname(f)) + options[:premailer_suffix] + File.extname(f))
|
112
99
|
end
|
113
100
|
|
114
101
|
STDERR.puts "#{File.basename(f)} --> #{File.join options[:premailer_dir], File.basename(out)}"
|
115
102
|
# raise "File already exists: #{out}" if File.exists?(out)
|
116
103
|
File.open(out, 'w') { |fw| fw.write(html) }
|
117
104
|
end
|
118
|
-
# end
|
119
105
|
end
|
120
106
|
STDERR.puts "Done"
|
121
107
|
end
|
122
108
|
end
|
123
109
|
|
110
|
+
|
111
|
+
desc 'Send html-letter(s) to recipients'
|
112
|
+
arg 'files', multiple: true, desc: "HTML-files to process"
|
113
|
+
command :bulksend do |c|
|
114
|
+
c.flag [:csv_email_column], default_value: 'email', type: String, desc: 'Colum name in csv with email addresses'
|
115
|
+
c.flag [:l, :list], default_value: nil, required: true, desc: "File with recipents (.txt - one email per line; .csv - with column named 'email')"
|
116
|
+
c.switch [:r, :shuffle], default_value: true, desc: "Send emails to recipients in random order"
|
117
|
+
c.flag [:t, :timeout], default_value: 1.0, type: Float, desc: "Wait given seconds between sending mails"
|
118
|
+
c.flag [:s, :subj], default_value: nil, desc: "Subject for mail. If blank then use <title> tag or html-file name"
|
119
|
+
# c.flag [:p, :pretend], default_value: nil, desc: "Run but do not make any real actions"
|
120
|
+
|
121
|
+
c.action do |global_options, options, args|
|
122
|
+
file_type = File.extname(options[:list]).gsub('.', '').strip.downcase
|
123
|
+
|
124
|
+
case file_type
|
125
|
+
when 'csv'
|
126
|
+
require 'csv'
|
127
|
+
|
128
|
+
rows = CSV.table(options[:list], skip_blanks: true)
|
129
|
+
total_count = rows.size
|
130
|
+
email_column = options[:csv_email_column].to_sym
|
131
|
+
|
132
|
+
STDERR.puts "Warning: shuffle option not yer implemented for CSV" if options[:shuffle]
|
133
|
+
|
134
|
+
rows.each_with_index do |row, index|
|
135
|
+
args.each do |f|
|
136
|
+
email = row[email_column]
|
137
|
+
Mailer2.mail2(f, email, options[:subj], global_options[:user]).deliver_now
|
138
|
+
STDERR.puts "(#{index+1}/#{total_count}) Email '#{File.basename(f)}' sent to #{email}"
|
139
|
+
sleep(options[:timeout]) if options[:timeout].present?
|
140
|
+
end
|
141
|
+
end
|
142
|
+
else
|
143
|
+
# STDERR.puts
|
144
|
+
lines = File.readlines(options[:list])
|
145
|
+
lines = lines.reject { |x| x.strip.blank? }
|
146
|
+
lines = lines.shuffle if options[:shuffle]
|
147
|
+
total_count = lines.size
|
148
|
+
lines.each_with_index do |line, index|
|
149
|
+
email = line.strip
|
150
|
+
if email.present?
|
151
|
+
args.each do |f|
|
152
|
+
Mailer2.mail2(f, email, options[:subj], global_options[:user]).deliver_now
|
153
|
+
# STDERR.print '.'
|
154
|
+
STDERR.puts "(#{index+1}/#{total_count}) Email '#{File.basename(f)}' sent to #{email}"
|
155
|
+
|
156
|
+
sleep(options[:timeout]) if options[:timeout].present?
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
STDERR.puts "Done"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
124
166
|
exit run(ARGV)
|
data/html2mail.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["e.vakhromtsev@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{html to mail converter}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{Console tool which generates html/eml stuff for your newsletters from html-files (support images in separate files)}
|
14
14
|
spec.homepage = "https://github.com/zuf/html2mail"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
23
|
# end
|
24
24
|
|
25
|
+
spec.required_ruby_version = '>= 1.9.1'
|
26
|
+
|
25
27
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
28
|
spec.bindir = "bin"
|
27
29
|
spec.executables = "html2mail" #spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -35,4 +37,5 @@ Gem::Specification.new do |spec|
|
|
35
37
|
spec.add_development_dependency "bundler", "~> 1.10"
|
36
38
|
spec.add_development_dependency "rake", "~> 10.0"
|
37
39
|
spec.add_development_dependency "minitest", "~> 5.8"
|
40
|
+
spec.add_development_dependency "simplecov", "~> 0.11"
|
38
41
|
end
|
data/lib/html2mail/mailer2.rb
CHANGED
@@ -3,38 +3,32 @@ require "action_mailer/base"
|
|
3
3
|
require 'premailer'
|
4
4
|
|
5
5
|
class Mailer2 < ActionMailer::Base
|
6
|
-
|
7
|
-
def prepare_html(html_file)
|
8
|
-
Premailer.new(html_file, :warn_level => Premailer::Warnings::SAFE).to_inline_css
|
9
|
-
end
|
10
|
-
|
11
6
|
def mail2(html_file, email, subject, from=nil)
|
12
7
|
premailer = Premailer.new(html_file, :warn_level => Premailer::Warnings::SAFE)
|
13
|
-
# STDOUT.puts premailer.to_inline_css
|
14
8
|
doc = Nokogiri::HTML(premailer.to_inline_css)
|
15
|
-
# doc = File.open(html_file) { |f| Nokogiri::XML(f) }
|
16
9
|
|
17
10
|
doc.css('img').each do |img|
|
18
11
|
path = img['src']
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
filesystem_path = File.expand_path(path, File.dirname(html_file))
|
13
|
+
if File.readable?(filesystem_path)
|
14
|
+
STDERR.puts "Process img: #{path}"
|
15
|
+
attachments.inline[File.basename(path)] = File.read(filesystem_path)
|
16
|
+
img['src'] = attachments.inline[File.basename(path)].url
|
17
|
+
end
|
22
18
|
end
|
23
19
|
|
24
20
|
head_title = doc.css('head title')
|
25
|
-
subject ||= head_title.text
|
26
|
-
subject ||= File.basename(html_file)
|
21
|
+
subject ||= head_title.text if head_title.present?
|
22
|
+
subject ||= File.basename(html_file, File.extname(html_file))
|
27
23
|
|
28
24
|
html = doc.to_s.html_safe
|
29
25
|
|
30
26
|
from ||= email
|
31
27
|
|
32
|
-
|
28
|
+
mail from: from, to: email, subject: subject do |format|
|
33
29
|
format.text { render plain: premailer.to_plain_text }
|
34
30
|
format.html { render html: html }
|
35
31
|
end
|
36
|
-
|
37
|
-
return m
|
38
32
|
end
|
39
33
|
end
|
40
34
|
|
data/lib/html2mail/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html2mail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Egor Vakhromtsev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -108,8 +108,22 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '5.8'
|
111
|
-
|
112
|
-
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.11'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.11'
|
125
|
+
description: Console tool which generates html/eml stuff for your newsletters from
|
126
|
+
html-files (support images in separate files)
|
113
127
|
email:
|
114
128
|
- e.vakhromtsev@gmail.com
|
115
129
|
executables:
|
@@ -142,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
156
|
requirements:
|
143
157
|
- - ">="
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
159
|
+
version: 1.9.1
|
146
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
161
|
requirements:
|
148
162
|
- - ">="
|