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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/dcidev_mailer/rails_mailer.rb', line 12
def email(html_body: "", header_url: "", footer_url: "", file_attachments: nil, to: nil, cc: nil, bcc: nil, from: nil, subject: "", template_path: "")
raise DcidevMailer::Errors::InvalidRecipients unless to.present?
raise DcidevMailer::Errors::InvalidBody unless html_body.present? && html_body.is_a?(String)
raise DcidevMailer::Errors::InvalidTemplate unless template_path.present?
wording, images = DcidevMailer.format_image_from_html(html_body)
locals = { wording: wording, header: nil, footer: nil }
locals, _ = DcidevMailer.(header_url: , footer_url: , locals: locals, images: images) if .present? || .present?
file_attachments = DcidevMailer.format_attachments(file_attachments) if file_attachments.present?
if file_attachments.present?
file_attachments.each do |a|
attachments[a[:name].to_s] = a[:content] unless a[:content].nil?
end
end
begin
= File.read(DcidevUtility.download_to_file())
= MimeMagic.by_magic()
attachments.inline['header'] =
attachments.inline['header']['content-type'] =
attachments.inline['header']['content-id'] = '<header>'
rescue => _
end
begin
= File.read(DcidevUtility.download_to_file())
= MimeMagic.by_magic()
attachments.inline['footer'] =
attachments.inline['footer']['content-type'] =
attachments.inline['footer']['content-id'] = '<footer>'
rescue => _
end
mail(
to: to,
cc: cc,
bcc: bcc,
subject: subject,
format: "text/html",
from: from,
) do |format|
format.html {
render locals: locals, html: ActionController::Base.new.render_to_string(template: template_path, locals: locals)
}
end
end
|