dcidev_mailer 0.0.8 → 0.0.9
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 +99 -88
- data/lib/dcidev_mailer/mandrill.rb +8 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed94880843b2769154af5f080cd85ecedbe73889f50da7d2f8d93745140264df
|
4
|
+
data.tar.gz: fe43144786157d05b25b80a1bfe2a6efd7b5c5396846a5c466018fd57e6a4a06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d022a4bfd340978d3a1b652a33cb9153b477eb98ad85a449599c87578f32b64cf5079b3ce4aed2ff06e6dd13158b32357e68c5f992424275b6819da61f60b3ab
|
7
|
+
data.tar.gz: 83d280862d6434e7c46151fcb17eaf90cec0ae77a630092c3ab785f7ec9f8f1f4afba346448db557a678fdbf684dd5a1789b2d500748d4dd275448e8e79d5cf4
|
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,65 +77,72 @@ 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,
|
95
|
+
bcc: nil,
|
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,
|
133
|
+
bcc: nil,
|
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
|
|
@@ -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,
|