dcidev_mailer 0.0.1
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/README.md +1 -0
- data/lib/dcidev_mailer/mandrill.rb +33 -0
- data/lib/dcidev_mailer/rails.rb +29 -0
- data/lib/dcidev_mailer.rb +56 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7ac7c10ec0396e09c6aca4d9fcb2139aab564278db919bd3bacd296ba2c39cfe
|
4
|
+
data.tar.gz: 378f826df467a228894e80d208f0f03fb15ebd34208c34f66140c922d8f654e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aabb088036f419ea923e8b461726e25b6e6a67b234f2aeab1556590d7d26fe0183367bb7f8a421bc4f95a79b6476f77e76d54e981ca6888602513756bed04b77
|
7
|
+
data.tar.gz: 149c14c2b6c1f56d73143ba9c1c08196c5609bca5edc5b6b7ea490fdb7c5842e1890a8ee4ccbb946ddba1cf7aa8d9555e53193d73ba099889c9d8bd944fba113
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
dcidev_mailer
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "mandrill"
|
2
|
+
|
3
|
+
module DcidevMailer
|
4
|
+
class Mandrill < MandrillMailer::MessageMailer
|
5
|
+
default from: ENV['DEFAULT_EMAIL_SENDER']
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def send_email(subject: "", html_body: "", to: nil, from: nil, attachments: nil, email_template_path: "", header_url: "", footer_url: "")
|
9
|
+
ac = ActionController::Base.new
|
10
|
+
wording, images = DcidevMailer.format_image_from_html(html_body)
|
11
|
+
locals = {wording: wording, header: nil, footer: nil}
|
12
|
+
locals, images = DcidevMailer.format_header_footer(header_url: header_url, footer_url: footer_url, locals: locals, images: images) if header_url.present? && footer_url.present?
|
13
|
+
html_body = ac.render_to_string(template: email_template_path, locals: locals)
|
14
|
+
attachments = DcidevMailer.format_attachments(attachments) if attachments.present?
|
15
|
+
self.send_mail(subject, to, html_body, attachments, images, from).deliver_now
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_mail(subject, to, html, attachments = nil, images = nil, from = nil)
|
19
|
+
mandrill_mail subject: subject,
|
20
|
+
from: from,
|
21
|
+
# to: "dev.puntodamar@gmail.com",
|
22
|
+
to: to,
|
23
|
+
# to: { email: invitation.email, name: 'Honored Guest' },
|
24
|
+
html: html,
|
25
|
+
view_content_link: true,
|
26
|
+
important: true,
|
27
|
+
inline_css: true,
|
28
|
+
attachments: attachments,
|
29
|
+
images: images
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'mail'
|
2
|
+
|
3
|
+
module DcidevMailer
|
4
|
+
class Rails < ApplicationMailer
|
5
|
+
default from: ENV['DEFAULT_EMAIL_SENDER']
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def email(html_body: "", header_url: "", footer_url: "", file_attachments: nil, to: "", from: nil, subject: "")
|
9
|
+
wording, images = DcidevMailer.format_image_from_html(html_body)
|
10
|
+
locals = {wording: wording, header: nil, footer: nil}
|
11
|
+
locals, images = DcidevMailer.format_header_footer(header_url: header_url, footer_url: footer_url, locals: locals, images: images) if header_url.present? && footer_url.present?
|
12
|
+
|
13
|
+
if file_attachments.present?
|
14
|
+
file_attachments.each do |a|
|
15
|
+
attachments[a[:name].to_s] = a[:content] unless a[:content].nil?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attachments.inline['header'] = File.read(Utility.download_to_file(header_url)) rescue nil if header_url.present?
|
20
|
+
attachments.inline['footer'] = File.read(Utility.download_to_file(footer_url)) rescue nil if footer_url.present?
|
21
|
+
|
22
|
+
mail(to: to, subject: subject, format: "text/html", from: from) do |format|
|
23
|
+
format.html {
|
24
|
+
render locals: locals
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module DcidevMailer
|
2
|
+
class << self
|
3
|
+
def format_image_from_html(html)
|
4
|
+
|
5
|
+
images = []
|
6
|
+
body_html = Nokogiri::HTML(html)
|
7
|
+
temp = body_html
|
8
|
+
if ENV["USE_MANDRILL_MAILER"].to_i == 1
|
9
|
+
temp.search("img").each_with_index do |img, i|
|
10
|
+
cid = "body_image_#{i}"
|
11
|
+
images.push({content: nil, encoded_content: DcidevUtility.base64_encoded_string(img["src"]), type: DcidevUtility.base64_extension(img["src"]), name: cid})
|
12
|
+
body_html.search("img")[i]["src"] = 'cid:' + cid
|
13
|
+
end
|
14
|
+
end
|
15
|
+
[body_html.search("body")[0].children.to_html, images]
|
16
|
+
end
|
17
|
+
|
18
|
+
def format_attachments(attachments)
|
19
|
+
formatted = []
|
20
|
+
attachments.each do |a|
|
21
|
+
begin
|
22
|
+
filetype = MimeMagic.by_magic(a[:file]).type.to_s
|
23
|
+
content = a[:file].read
|
24
|
+
name = "#{a[:filename]}.#{filetype.split("/")[1]}"
|
25
|
+
att = {
|
26
|
+
content: content,
|
27
|
+
name: name,
|
28
|
+
}
|
29
|
+
|
30
|
+
att[:type] = filetype if ENV["USE_MANDRILL_MAILER"].to_i == 0
|
31
|
+
formatted << att
|
32
|
+
rescue => _
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
formatted
|
37
|
+
end
|
38
|
+
|
39
|
+
def format_header_footer(header_url: "", footer_url: "", locals: {}, images: {})
|
40
|
+
[{name: "header", url: header_url}, {name: "footer", url: footer_url}].each do |i|
|
41
|
+
return if i[:url].nil?
|
42
|
+
begin
|
43
|
+
extension, encoded, _ = DcidevUtility.file_url_to_base64(i[:url])
|
44
|
+
locals[i[:name].to_sym] = "cid:#{i[:name]}"
|
45
|
+
images.push({content: encoded, encoded_content: encoded, type: extension, name: i[:name]})
|
46
|
+
rescue => _
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return [locals, images]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dcidev_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Punto Damar P
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mimemagic
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dcidev_utility
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Testing phase
|
42
|
+
email:
|
43
|
+
- punto@privyid.tech
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- lib/dcidev_mailer.rb
|
50
|
+
- lib/dcidev_mailer/mandrill.rb
|
51
|
+
- lib/dcidev_mailer/rails.rb
|
52
|
+
homepage:
|
53
|
+
licenses: []
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.0.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Commonly used email codes
|
74
|
+
test_files: []
|