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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4c888484deeed90b4688c4b671c3dcce1c0cd2e6c8246ef60a7779cfb73bd9f
4
- data.tar.gz: 4d90779c9e75604a863487d060db02b8170de0cbdd2785e61478d4b3c20cf0e9
3
+ metadata.gz: 92cf0dc63352424606b22ecfccce05ea3daa10fce535898e1e37c85095735ff2
4
+ data.tar.gz: 15ed559e1470ce64ed6f49b6dd7445ff27e7048b4445fb600e16392a18246430
5
5
  SHA512:
6
- metadata.gz: 9eca49e59d46f4bb88c6870c3bcd5bb468d6c8ce44c3f346dfbfc29cada557840fb8f3f7af5f65478ee38cda297063e9725b298b7aef423dc37e342870ec9b5a
7
- data.tar.gz: 53a043bb683096d6f2d992d49da00c636beb7548753fe3676bbd71a81dea5830f8284e8677657c128a47d7754768f7650d4de2ecc1124f9260f35096ef32bbd4
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 = :smtp
30
+ ActionMailer::Base.delivery_method =: smtp
31
31
 
32
32
  # change it to your helper class name
33
- ActionMailer::Base.add_delivery_method :mandrill_mailer, MandrillMailer
34
-
35
- # uncomment if neccessary
36
- smtp_settings = {
37
- address: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_ADDRESS'] : ENV["MAILER_SMTP_ADDRESS"],
38
- # authentication: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? 'plain' : nil,
39
- domain: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_DOMAIN'] : ENV["MAILER_SMTP_DOMAIN"],
40
- enable_starttls_auto: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? true : false,
41
- tls: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? true : false,
42
- # password: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_PASSWORD'] : ENV["MAILER_SMTP_PASSWORD"],
43
- port: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_PORT'] : ENV["MAILER_SMTP_PORT"],
44
- # user_name: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_USERNAME'] : ENV["MAILER_SMTP_USERNAME"],
45
- # openssl_verify_mode: "none",}
46
-
47
- if ENV["USE_MANDRILL_MAILER"].to_i == 1
48
- smtp_settings[:authentication] = 'plain'
49
- smtp_settings[:password] = ENV['MANDRILL_SMTP_PASSWORD']
50
- smtp_settings[:user_name] = ENV['MANDRILL_SMTP_USERNAME']
51
- end
52
-
53
- ActionMailer::Base.smtp_settings = smtp_settings
54
-
55
- ActionMailer::Base.default_url_options = { :host => ENV["BASE_URL_FE"] }
56
- ActionMailer::Base.register_preview_interceptor(ActionMailer::InlinePreviewInterceptor)
57
-
58
- # Don't care if the mailer can't send.
59
- ActionMailer::Base.raise_delivery_errors = true
60
- ActionMailer::Base.perform_deliveries = true
61
- ActionMailer::Base.perform_caching = false
62
-
63
- MandrillMailer.configure do |config|
64
- config.api_key = ENV["MANDRILL_SMTP_PASSWORD"]
65
- config.deliver_later_queue_name = :default
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
- class MandrillMailer
77
- class << self
78
- def send_email(customer: nil, email_template: nil, attachments: nil, description: nil)
79
- raise "invalid customer" if customer.nil?
80
- raise "invalid template" if email_template.nil?
81
- begin
82
- response = ::DcidevMailer::Mandrill.send_email(
83
- subject: email_template.subject,
84
- html_body: MailerHelper.format_wording(email_template.wording, customer),
85
- header_url: email_template.header.try(:url),
86
- footer_url: email_template.footer.try(:url),
87
- to: customer.email,
88
- cc: nil,
89
- bcc: nil,
90
- from: ENV['DEFAULT_EMAIL_SENDER'],
91
- attachments: attachments,
92
- email_template_path: "mail/blast.html.erb" # specify template file location
93
- )
94
- rescue => e
95
- error_message = "[SEND EMAIL] " + e.try(:to_s)
96
- ensure
97
- 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?
98
- ApplicationHistory.log(description: error_message || description, application: customer.application)
99
- end
100
- end endend
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
- class << self
107
- def email(customer: nil, template: nil, file_attachments: nil, description: nil)
108
- begin
109
- raise "invalid customer" if customer.nil?
110
- raise "invalid template" if template.nil?
111
- raise "email is empty" if customer.email.nil?
112
-
113
- wording, _ = DcidevMailer.format_image_from_html(template.wording)
114
- wording = MailerHelper.format_wording(wording,customer)
115
-
116
- DcidevMailer::RailsMailer.email(
117
- html_body: wording,
118
- header_url: template.header.try(:url),
119
- footer_url: template.footer.try(:url),
120
- file_attachments: file_attachments,
121
- to: customer.email,
122
- cc: nil,
123
- bcc: nil,
124
- subject: template.subject,
125
- from: ENV['DEFAULT_EMAIL_SENDER'],
126
- template_path: "mail/blast.html.erb" # specify template file location
127
- )
128
- rescue => e
129
- error_message = "[SEND EMAIL] " + e.try(:to_s)
130
- ensure
131
- EmailHistory.create(status: error_message.present? ? :failed : :sent, error_message: error_message, application: customer.application, template: template, form_cetak_attachment: file_attachments.present?)
132
- ApplicationHistory.log(description: error_message || description, application: customer.application)
133
- end
134
- end end
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 "mandrill"
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: "", html_body: "", to: nil, from: nil, attachments: nil, email_template_path: "", header_url: "", footer_url: "")
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
- from: from,
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
- am.attachments[a[:name].to_s] = a[:content] unless a[:content].nil?
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(Utility.download_to_file(header_url)) rescue nil if header_url.present?
27
- attachments.inline['footer'] = File.read(Utility.download_to_file(footer_url)) rescue nil if footer_url.present?
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.8
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 00:00:00.000000000 Z
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.2.3
73
+ rubygems_version: 3.0.6
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Commonly used email codes