dcidev_mailer 0.0.8 → 0.0.12
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/README.md +105 -88
- data/lib/dcidev_mailer/mandrill.rb +8 -6
- data/lib/dcidev_mailer/rails_mailer.rb +5 -4
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92cf0dc63352424606b22ecfccce05ea3daa10fce535898e1e37c85095735ff2
|
|
4
|
+
data.tar.gz: 15ed559e1470ce64ed6f49b6dd7445ff27e7048b4445fb600e16392a18246430
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b27fd936d828b8f08b1a06f0f77bed785a96d6770fa9762dfe4de8d9ade9a02687f9eec3537e4ab40caa0c07fc62701f00cf73184fcfdc30a3c5139d4f71a0fa
|
|
7
|
+
data.tar.gz: 424b1ab0c90d99a540fa508a1be07c04c50d1405285354793d33c5130db8395a466ea24ae17a250af2ae20562a87ea08ac29504f8f824916c215fb820267d3b2
|
data/README.md
CHANGED
|
@@ -27,42 +27,46 @@ MAILER_SMTP_TLS=
|
|
|
27
27
|
|
|
28
28
|
Add this to `config/initializer/mailer.rb`
|
|
29
29
|
```ruby
|
|
30
|
-
ActionMailer::Base.delivery_method
|
|
30
|
+
ActionMailer::Base.delivery_method =: smtp
|
|
31
31
|
|
|
32
32
|
# change it to your helper class name
|
|
33
|
-
ActionMailer::Base.add_delivery_method
|
|
34
|
-
|
|
35
|
-
# uncomment
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
ActionMailer::Base.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
ActionMailer::Base.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
33
|
+
ActionMailer::Base.add_delivery_method: mandrill_mailer, MandrillMailer
|
|
34
|
+
|
|
35
|
+
# uncomment
|
|
36
|
+
if neccessary
|
|
37
|
+
smtp_settings = {
|
|
38
|
+
address: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_ADDRESS'] : ENV["MAILER_SMTP_ADDRESS"],
|
|
39
|
+
# authentication: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? 'plain' : nil,
|
|
40
|
+
domain: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_DOMAIN'] : ENV["MAILER_SMTP_DOMAIN"],
|
|
41
|
+
enable_starttls_auto: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? true : false,
|
|
42
|
+
tls: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? true : false,
|
|
43
|
+
# password: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_PASSWORD'] : ENV["MAILER_SMTP_PASSWORD"],
|
|
44
|
+
port: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_PORT'] : ENV["MAILER_SMTP_PORT"],
|
|
45
|
+
# user_name: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_USERNAME'] : ENV["MAILER_SMTP_USERNAME"],
|
|
46
|
+
# openssl_verify_mode: "none",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if ENV["USE_MANDRILL_MAILER"].to_i == 1
|
|
50
|
+
smtp_settings[: authentication] = 'plain'
|
|
51
|
+
smtp_settings[: password] = ENV['MANDRILL_SMTP_PASSWORD']
|
|
52
|
+
smtp_settings[: user_name] = ENV['MANDRILL_SMTP_USERNAME']
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
ActionMailer::Base.smtp_settings = smtp_settings
|
|
56
|
+
|
|
57
|
+
ActionMailer::Base.default_url_options = {
|
|
58
|
+
: host => ENV["BASE_URL_FE"]
|
|
59
|
+
}
|
|
60
|
+
ActionMailer::Base.register_preview_interceptor(ActionMailer::InlinePreviewInterceptor)
|
|
61
|
+
|
|
62
|
+
# Don 't care if the mailer can't send.
|
|
63
|
+
ActionMailer::Base.raise_delivery_errors = true
|
|
64
|
+
ActionMailer::Base.perform_deliveries = true
|
|
65
|
+
ActionMailer::Base.perform_caching = false
|
|
66
|
+
|
|
67
|
+
MandrillMailer.configure do |config |
|
|
68
|
+
config.api_key = ENV["MANDRILL_SMTP_PASSWORD"]
|
|
69
|
+
config.deliver_later_queue_name =: default
|
|
66
70
|
end
|
|
67
71
|
```
|
|
68
72
|
|
|
@@ -73,68 +77,81 @@ end
|
|
|
73
77
|
|
|
74
78
|
|
|
75
79
|
```ruby
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
80
|
+
require 'dcidev_mailer/mandrill'
|
|
81
|
+
|
|
82
|
+
class MandrillMailer
|
|
83
|
+
class << self
|
|
84
|
+
def send_email(customer: nil, email_template: nil, attachments: nil, description: nil)
|
|
85
|
+
raise "invalid customer"if customer.nil?
|
|
86
|
+
raise "invalid template" if email_template.nil ?
|
|
87
|
+
begin
|
|
88
|
+
response = ::DcidevMailer::Mandrill.send_email(
|
|
89
|
+
subject: email_template.subject,
|
|
90
|
+
html_body: MailerHelper.format_wording(email_template.wording, customer),
|
|
91
|
+
header_url: email_template.header.try(: url),
|
|
92
|
+
footer_url: email_template.footer.try(: url),
|
|
93
|
+
to: customer.email,
|
|
94
|
+
cc: nil, # can be a string / array
|
|
95
|
+
bcc: nil, # can be a string / array
|
|
96
|
+
from: ENV['DEFAULT_EMAIL_SENDER'],
|
|
97
|
+
attachments: attachments,
|
|
98
|
+
email_template_path: "mail/blast.html.erb"
|
|
99
|
+
# specify template file location
|
|
100
|
+
)
|
|
101
|
+
rescue => e
|
|
102
|
+
error_message = "[SEND EMAIL] " + e.try(: to_s)
|
|
103
|
+
ensure
|
|
104
|
+
EmailHistory.create(application: customer.application, template: email_template, status: response[0]["status"] == "sent" ? : sent:: failed, mail_provider_id: response[0]["_id"], form_cetak_attachment: attachments.present ? , error_message : response[0]["reject_reason"]) if response.present ?
|
|
105
|
+
ApplicationHistory.log(description: error_message || description, application: customer.application)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
101
109
|
```
|
|
102
110
|
|
|
103
111
|
### Action Mailer Example
|
|
104
112
|
```ruby
|
|
113
|
+
require 'dcidev_mailer/rails_mailer'
|
|
114
|
+
|
|
105
115
|
class MortgageMailer
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
116
|
+
class << self
|
|
117
|
+
def email(customer: nil, template: nil, file_attachments: nil, description: nil)
|
|
118
|
+
begin
|
|
119
|
+
raise "invalid customer" if customer.nil?
|
|
120
|
+
raise "invalid template" if template.nil?
|
|
121
|
+
raise "email is empty" if customer.email.nil?
|
|
122
|
+
|
|
123
|
+
wording, _ = DcidevMailer.format_image_from_html(template.wording)
|
|
124
|
+
wording = MailerHelper.format_wording(wording,customer)
|
|
125
|
+
|
|
126
|
+
DcidevMailer::RailsMailer.email(
|
|
127
|
+
html_body: wording,
|
|
128
|
+
header_url: template.header.try(:url),
|
|
129
|
+
footer_url: template.footer.try(:url),
|
|
130
|
+
file_attachments: file_attachments,
|
|
131
|
+
to: customer.email,
|
|
132
|
+
cc: nil, # can be a string / array
|
|
133
|
+
bcc: nil, # can be a string / array
|
|
134
|
+
subject: template.subject,
|
|
135
|
+
from: ENV['DEFAULT_EMAIL_SENDER'],
|
|
136
|
+
template_path: "mail/blast.html.erb" # specify template file location
|
|
137
|
+
)
|
|
138
|
+
rescue => e
|
|
139
|
+
error_message = "[SEND EMAIL] " + e.try(:to_s)
|
|
140
|
+
ensure
|
|
141
|
+
EmailHistory.create(status: error_message.present? ? :failed : :sent, error_message: error_message, application: customer.application, template: template, form_cetak_attachment: file_attachments.present?)
|
|
142
|
+
ApplicationHistory.log(description: error_message || description, application: customer.application)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
135
146
|
end
|
|
136
147
|
```
|
|
137
148
|
|
|
149
|
+
### Sending Attachments
|
|
150
|
+
The attachment is an array of hashes containing attachment file and filename
|
|
151
|
+
```ruby
|
|
152
|
+
attachments = [{file: DcidevUtility.download_to_file(self.ktp.url), filename: self.reference_number}]
|
|
153
|
+
```
|
|
154
|
+
|
|
138
155
|
### Helpers
|
|
139
156
|
```ruby
|
|
140
157
|
# convert all image URL in <img src="url"> to <img src="cid:xxxx">
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'mandrill'
|
|
2
2
|
|
|
3
3
|
module DcidevMailer
|
|
4
4
|
class Mandrill < MandrillMailer::MessageMailer
|
|
5
5
|
default from: ENV['DEFAULT_EMAIL_SENDER']
|
|
6
6
|
|
|
7
7
|
class << self
|
|
8
|
-
def send_email(subject:
|
|
8
|
+
def send_email(subject: '', html_body: '', to: nil, cc: nil, bcc: nil, from: nil, attachments: nil, email_template_path: '', header_url: '', footer_url: '')
|
|
9
9
|
ac = ActionController::Base.new
|
|
10
10
|
wording, images = DcidevMailer.format_image_from_html(html_body)
|
|
11
|
-
locals = {wording: wording, header: nil, footer: nil}
|
|
11
|
+
locals = { wording: wording, header: nil, footer: nil }
|
|
12
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
13
|
html_body = ac.render_to_string(template: email_template_path, locals: locals)
|
|
14
14
|
attachments = DcidevMailer.format_attachments(attachments) if attachments.present?
|
|
15
|
-
self.send_mail(subject, to, html_body, attachments, images, from).deliver_now
|
|
15
|
+
self.send_mail(subject, to, cc, bcc, html_body, attachments, images, from).deliver_now
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def send_mail(subject, to, html, attachments = nil, images = nil, from = nil)
|
|
18
|
+
def send_mail(subject, to, cc, bcc, html, attachments = nil, images = nil, from = nil)
|
|
19
19
|
mandrill_mail subject: subject,
|
|
20
|
-
|
|
20
|
+
from: from,
|
|
21
21
|
# to: "dev.puntodamar@gmail.com",
|
|
22
22
|
to: to,
|
|
23
|
+
cc: cc,
|
|
24
|
+
bcc: bcc,
|
|
23
25
|
# to: { email: invitation.email, name: 'Honored Guest' },
|
|
24
26
|
html: html,
|
|
25
27
|
view_content_link: true,
|
|
@@ -16,15 +16,16 @@ module DcidevMailer
|
|
|
16
16
|
|
|
17
17
|
locals = { wording: wording, header: nil, footer: nil }
|
|
18
18
|
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?
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
file_attachments = DcidevMailer.format_attachments(file_attachments) if file_attachments.present?
|
|
20
21
|
if file_attachments.present?
|
|
21
22
|
file_attachments.each do |a|
|
|
22
|
-
|
|
23
|
+
attachments[a[:name].to_s] = a[:content] unless a[:content].nil?
|
|
23
24
|
end
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
attachments.inline['header'] = File.read(
|
|
27
|
-
attachments.inline['footer'] = File.read(
|
|
27
|
+
attachments.inline['header'] = File.read(DcidevUtility.download_to_file(header_url)) rescue nil if header_url.present?
|
|
28
|
+
attachments.inline['footer'] = File.read(DcidevUtility.download_to_file(footer_url)) rescue nil if footer_url.present?
|
|
28
29
|
|
|
29
30
|
mail(
|
|
30
31
|
to: to,
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dcidev_mailer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Punto Damar P
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-01-
|
|
11
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mimemagic
|
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
70
70
|
- !ruby/object:Gem::Version
|
|
71
71
|
version: '0'
|
|
72
72
|
requirements: []
|
|
73
|
-
rubygems_version: 3.
|
|
73
|
+
rubygems_version: 3.0.6
|
|
74
74
|
signing_key:
|
|
75
75
|
specification_version: 4
|
|
76
76
|
summary: Commonly used email codes
|