11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/html2mail/mailer2.rb', line 11
def mail2(html_file, email, subject, from=nil)
premailer = Premailer.new(html_file, :warn_level => Premailer::Warnings::SAFE)
doc = Nokogiri::HTML(premailer.to_inline_css)
doc.css('img').each do |img|
path = img['src']
STDERR.puts "Process img: #{path}"
attachments.inline[File.basename(path)] = File.read(File.expand_path(path, File.dirname(html_file)))
img['src'] = attachments.inline[File.basename(path)].url
end
head_title = doc.css('head title')
subject ||= head_title.text if head_title.present?
subject ||= File.basename(html_file)
html = doc.to_s.html_safe
from ||= email
m = mail from: from, to: email, subject: subject do |format|
format.text { render plain: premailer.to_plain_text }
format.html { render html: html }
end
return m
end
|