html2mail 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/html2mail +124 -0
- data/bin/setup +7 -0
- data/html2mail.gemspec +38 -0
- data/lib/html2mail/mailer2.rb +40 -0
- data/lib/html2mail/version.rb +3 -0
- data/lib/html2mail.rb +6 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: afc0e94603f45ac67c66da6dd104054909f16fc2
|
4
|
+
data.tar.gz: d5ee1f834a7efa9681894ade1b26f2a502cb3613
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa1cb0a4922ae2a892ef3a4f9b84800b859de06fa8870993119515c098138827a4fd5ebf254013854ca856225ffbe2014091f9956a505d907dcf1ddebcb7aab3
|
7
|
+
data.tar.gz: 7d9d017bb889ae93781251cf747e261d83e542ca37129bd45265d7a8a9248447151510f947d4b91eb87d0827d4153a76b450256bac3370ec9aa18a1b17e1f6a1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Egor Vakhromtsev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# html2mail
|
2
|
+
|
3
|
+
Generates html/eml stuff for your newsletters from generic html (with images in separate files).
|
4
|
+
|
5
|
+
|
6
|
+
## Examples
|
7
|
+
|
8
|
+
Show inline help:
|
9
|
+
|
10
|
+
`bundle exec bin/html2mail help`
|
11
|
+
`bundle exec bin/html2mail send --help`
|
12
|
+
|
13
|
+
|
14
|
+
Convert html with images to .eml
|
15
|
+
|
16
|
+
`bundle exec bin/html2mail convert /path/to/newsletter.html`
|
17
|
+
|
18
|
+
or all html files at once:
|
19
|
+
|
20
|
+
`bundle exec bin/html2mail convert /path/to/*.html`
|
21
|
+
|
22
|
+
|
23
|
+
Save "premailed" HTML files (convert css to inline styles):
|
24
|
+
|
25
|
+
`bundle exec bin/html2mail prepare /path/to/*.html`
|
26
|
+
|
27
|
+
|
28
|
+
Send test emails and use stored config for SMTP server:
|
29
|
+
|
30
|
+
`bundle exec bin/html2mail send /path/to/newsletters/*.html --to your@domain.com --domain=example.com --user=user@example.com --password=princess1 --subj='Test mail'`
|
31
|
+
|
32
|
+
Init SMTP config:
|
33
|
+
|
34
|
+
> WARNING: Password stored as plain text in config file `.html2mail.yml` file in $HOME for Linux
|
35
|
+
|
36
|
+
`bundle exec bin/html2mail --domain=example.com --user=user@example.com --password=princess1 initconfig`
|
37
|
+
|
38
|
+
Send test emails and use stored config for SMTP server:
|
39
|
+
|
40
|
+
`bundle exec bin/html2mail send /path/to/newsletters/*.html --to your@domain.com`
|
41
|
+
|
42
|
+
|
43
|
+
## Based on gems
|
44
|
+
|
45
|
+
* ActionMailer
|
46
|
+
* premailer
|
47
|
+
* nokogiri
|
48
|
+
* GLI
|
49
|
+
|
50
|
+
|
51
|
+
### License
|
52
|
+
|
53
|
+
MIT License
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "html2mail"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/html2mail
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "html2mail"
|
5
|
+
require 'gli'
|
6
|
+
|
7
|
+
include GLI::App
|
8
|
+
|
9
|
+
|
10
|
+
program_desc 'Convert html file with images to e-mail'
|
11
|
+
|
12
|
+
# flag [:t, :sendtest], default_value: true
|
13
|
+
# flag [:f, :file], default_value: nil
|
14
|
+
|
15
|
+
# pre do |global_options, command, options, args|
|
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
|
24
|
+
|
25
|
+
config_file '.html2mail.yml'
|
26
|
+
|
27
|
+
pre do |global, command, options, args|
|
28
|
+
Mailer2.delivery_method = :smtp
|
29
|
+
Mailer2.smtp_settings = {:address => global[:domain],
|
30
|
+
:user_name => global[:user],
|
31
|
+
:password => global[:password],
|
32
|
+
:enable_starttls_auto => global[:starttls]}
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Sent email from html to given adress'
|
36
|
+
arg 'files', multiple: true, desc: "HTML-files to process"
|
37
|
+
command :send do |c|
|
38
|
+
c.flag [:t, :to], default_value: nil
|
39
|
+
c.flag [:s, :subj], default_value: nil
|
40
|
+
|
41
|
+
c.action do |global_options, options, args|
|
42
|
+
# STDERR.puts args
|
43
|
+
args.each do |f|
|
44
|
+
STDERR.puts "Start mail processing"
|
45
|
+
|
46
|
+
m= Mailer2.mail2 f, options[:to], options[:subj], global_options[:user]
|
47
|
+
m.deliver_now
|
48
|
+
|
49
|
+
STDERR.puts "Done"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
desc 'Convert HTML file with images to eml'
|
56
|
+
arg 'files', multiple: true, desc: "HTML-files to process"
|
57
|
+
command :convert do |c|
|
58
|
+
c.switch [:s, :stdout], default_value: false
|
59
|
+
c.flag [:o, :output], default_value: nil
|
60
|
+
|
61
|
+
c.action do |global_options, options, args|
|
62
|
+
# STDERR.puts "Processing: #{args}"
|
63
|
+
args.each do |f|
|
64
|
+
m = Mailer2.mail2 f, options[:to], options[:subj], global_options[:user]
|
65
|
+
|
66
|
+
html = m.to_s.html_safe
|
67
|
+
|
68
|
+
if options[:stdout]
|
69
|
+
STDOUT.puts html
|
70
|
+
else
|
71
|
+
if options[:output].present?
|
72
|
+
out = options[:output]
|
73
|
+
else
|
74
|
+
out = File.join(File.dirname(f), File.basename(f, File.extname(f)) + '.eml')
|
75
|
+
end
|
76
|
+
|
77
|
+
STDERR.puts "out: #{out}"
|
78
|
+
# raise "File already exists: #{out}" if File.exists?(out)
|
79
|
+
File.open(out, 'w') { |fw| fw.write(html) }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
STDERR.puts "Done"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
desc 'Convert HTML with premailer to more mail software compatible (converts css to style attributes)'
|
87
|
+
arg 'files', multiple: true, desc: "HTML-files to process"
|
88
|
+
command :prepare do |c|
|
89
|
+
c.switch [:s, :stdout], default_value: false
|
90
|
+
c.flag [:o, :output], default_value: nil
|
91
|
+
c.flag [:premailer_prefix], default_value: 'premailed_'
|
92
|
+
c.flag [:premailer_suffix], default_value: ''
|
93
|
+
c.flag [:premailer_dir], default_value: 'premailed'
|
94
|
+
|
95
|
+
c.action do |global_options, options, args|
|
96
|
+
STDERR.puts "Processing: #{args.join(', ')}"
|
97
|
+
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
|
+
html = Premailer.new(f, :warn_level => Premailer::Warnings::SAFE).to_inline_css.html_safe
|
102
|
+
|
103
|
+
if options[:stdout]
|
104
|
+
STDOUT.puts html
|
105
|
+
else
|
106
|
+
if options[:output].present?
|
107
|
+
out = options[:output]
|
108
|
+
else
|
109
|
+
premailed_dir = File.join(File.dirname(f), options[:premailer_dir])
|
110
|
+
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))
|
112
|
+
end
|
113
|
+
|
114
|
+
STDERR.puts "#{File.basename(f)} --> #{File.join options[:premailer_dir], File.basename(out)}"
|
115
|
+
# raise "File already exists: #{out}" if File.exists?(out)
|
116
|
+
File.open(out, 'w') { |fw| fw.write(html) }
|
117
|
+
end
|
118
|
+
# end
|
119
|
+
end
|
120
|
+
STDERR.puts "Done"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
exit run(ARGV)
|
data/bin/setup
ADDED
data/html2mail.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'html2mail/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "html2mail"
|
8
|
+
spec.version = Html2mail::VERSION
|
9
|
+
spec.authors = ["Egor Vakhromtsev"]
|
10
|
+
spec.email = ["e.vakhromtsev@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{html to mail converter}
|
13
|
+
spec.description = %q{Generates html/eml stuff for your newsletters from generic html (with images in separate files)}
|
14
|
+
spec.homepage = "https://github.com/zuf/html2mail"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# # delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "bin"
|
27
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "actionmailer", "~> 4.2"
|
31
|
+
spec.add_dependency "nokogiri", "~> 1.6"
|
32
|
+
spec.add_dependency "premailer", "~> 1.8"
|
33
|
+
spec.add_dependency "gli", "~> 2.13"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "minitest", "~> 5.8"
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "action_mailer"
|
2
|
+
require "action_mailer/base"
|
3
|
+
require 'premailer'
|
4
|
+
|
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
|
+
def mail2(html_file, email, subject, from=nil)
|
12
|
+
premailer = Premailer.new(html_file, :warn_level => Premailer::Warnings::SAFE)
|
13
|
+
# STDOUT.puts premailer.to_inline_css
|
14
|
+
doc = Nokogiri::HTML(premailer.to_inline_css)
|
15
|
+
# doc = File.open(html_file) { |f| Nokogiri::XML(f) }
|
16
|
+
|
17
|
+
doc.css('img').each do |img|
|
18
|
+
path = img['src']
|
19
|
+
STDERR.puts "Process img: #{path}"
|
20
|
+
attachments.inline[File.basename(path)] = File.read(File.expand_path(path, File.dirname(html_file)))
|
21
|
+
img['src'] = attachments.inline[File.basename(path)].url
|
22
|
+
end
|
23
|
+
|
24
|
+
head_title = doc.css('head title')
|
25
|
+
subject ||= head_title.text if head_title.present?
|
26
|
+
subject ||= File.basename(html_file)
|
27
|
+
|
28
|
+
html = doc.to_s.html_safe
|
29
|
+
|
30
|
+
from ||= email
|
31
|
+
|
32
|
+
m = mail from: from, to: email, subject: subject do |format|
|
33
|
+
format.text { render plain: premailer.to_plain_text }
|
34
|
+
format.html { render html: html }
|
35
|
+
end
|
36
|
+
|
37
|
+
return m
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/lib/html2mail.rb
ADDED
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html2mail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Egor Vakhromtsev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionmailer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: premailer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gli
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.13'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '5.8'
|
111
|
+
description: Generates html/eml stuff for your newsletters from generic html (with
|
112
|
+
images in separate files)
|
113
|
+
email:
|
114
|
+
- e.vakhromtsev@gmail.com
|
115
|
+
executables:
|
116
|
+
- console
|
117
|
+
- html2mail
|
118
|
+
- setup
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files: []
|
121
|
+
files:
|
122
|
+
- ".gitignore"
|
123
|
+
- ".travis.yml"
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/html2mail
|
130
|
+
- bin/setup
|
131
|
+
- html2mail.gemspec
|
132
|
+
- lib/html2mail.rb
|
133
|
+
- lib/html2mail/mailer2.rb
|
134
|
+
- lib/html2mail/version.rb
|
135
|
+
homepage: https://github.com/zuf/html2mail
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.4.5.1
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: html to mail converter
|
159
|
+
test_files: []
|
160
|
+
has_rdoc:
|