dcidev_mailer 0.0.9 → 0.0.13

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: ed94880843b2769154af5f080cd85ecedbe73889f50da7d2f8d93745140264df
4
- data.tar.gz: fe43144786157d05b25b80a1bfe2a6efd7b5c5396846a5c466018fd57e6a4a06
3
+ metadata.gz: 5a56a9c54429232d7fd7d01cc3f657534537ca554886d5d77aa30c8f7ae93567
4
+ data.tar.gz: 7404b2af018fe76212836484eb364b42ec5375c84d4f9a00844ae20ad2201c62
5
5
  SHA512:
6
- metadata.gz: d022a4bfd340978d3a1b652a33cb9153b477eb98ad85a449599c87578f32b64cf5079b3ce4aed2ff06e6dd13158b32357e68c5f992424275b6819da61f60b3ab
7
- data.tar.gz: 83d280862d6434e7c46151fcb17eaf90cec0ae77a630092c3ab785f7ec9f8f1f4afba346448db557a678fdbf684dd5a1789b2d500748d4dd275448e8e79d5cf4
6
+ metadata.gz: db523c536b6164e8830f4de07d94ccb00d27c8fa6341748747830dcb45e2d7a1e147a3226837457da585c2942caeea818ee39e25bd2d5623ce53d2947bc6fdbc
7
+ data.tar.gz: 85ac24510c11d94287baffe97b5a728badfb9ab8040297908a03061fc42c9db209cd04e8ee3c62391c6e7ff83bf11ff1db2123b7577b7099f27dc1584814f499
data/README.md CHANGED
@@ -27,13 +27,12 @@ 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
33
  ActionMailer::Base.add_delivery_method: mandrill_mailer, MandrillMailer
34
34
 
35
- # uncomment
36
- if neccessary
35
+ # uncomment if neccessary
37
36
  smtp_settings = {
38
37
  address: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_ADDRESS'] : ENV["MAILER_SMTP_ADDRESS"],
39
38
  # authentication: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? 'plain' : nil,
@@ -47,15 +46,15 @@ smtp_settings = {
47
46
  }
48
47
 
49
48
  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']
49
+ smtp_settings[:authentication] = 'plain'
50
+ smtp_settings[:password] = ENV['MANDRILL_SMTP_PASSWORD']
51
+ smtp_settings[:user_name] = ENV['MANDRILL_SMTP_USERNAME']
53
52
  end
54
53
 
55
54
  ActionMailer::Base.smtp_settings = smtp_settings
56
55
 
57
56
  ActionMailer::Base.default_url_options = {
58
- : host => ENV["BASE_URL_FE"]
57
+ host: ENV["BASE_URL_FE"]
59
58
  }
60
59
  ActionMailer::Base.register_preview_interceptor(ActionMailer::InlinePreviewInterceptor)
61
60
 
@@ -91,8 +90,8 @@ class MandrillMailer
91
90
  header_url: email_template.header.try(: url),
92
91
  footer_url: email_template.footer.try(: url),
93
92
  to: customer.email,
94
- cc: nil,
95
- bcc: nil,
93
+ cc: nil, # can be a string / array
94
+ bcc: nil, # can be a string / array
96
95
  from: ENV['DEFAULT_EMAIL_SENDER'],
97
96
  attachments: attachments,
98
97
  email_template_path: "mail/blast.html.erb"
@@ -129,12 +128,12 @@ class MortgageMailer
129
128
  footer_url: template.footer.try(:url),
130
129
  file_attachments: file_attachments,
131
130
  to: customer.email,
132
- cc: nil,
133
- bcc: nil,
131
+ cc: nil, # can be a string / array
132
+ bcc: nil, # can be a string / array
134
133
  subject: template.subject,
135
134
  from: ENV['DEFAULT_EMAIL_SENDER'],
136
135
  template_path: "mail/blast.html.erb" # specify template file location
137
- )
136
+ ).deliver_now
138
137
  rescue => e
139
138
  error_message = "[SEND EMAIL] " + e.try(:to_s)
140
139
  ensure
@@ -146,6 +145,12 @@ class MortgageMailer
146
145
  end
147
146
  ```
148
147
 
148
+ ### Sending Attachments
149
+ The attachment is an array of hashes containing attachment file and filename
150
+ ```ruby
151
+ attachments = [{file: DcidevUtility.download_to_file(self.ktp.url), filename: self.reference_number}]
152
+ ```
153
+
149
154
  ### Helpers
150
155
  ```ruby
151
156
  # convert all image URL in <img src="url"> to <img src="cid:xxxx">
@@ -155,6 +160,6 @@ DcidevMailer::format_image_from_html(html)
155
160
  DcidevMailer::format_attachments(attachments)
156
161
 
157
162
  # format email header & footer url to be embedded to html body
158
- # refer to class DcidevMailer::Mandrill or DcidevMailer::Rails to understand more of this method
163
+ # refer to class DcidevMailer::Mandrill or DcidevMailer::Rails for more details about the usage
159
164
  DcidevMailer::format_header_footer(header_url: "", footer_url: "", locals: {}, images: {})
160
165
  ```
@@ -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,
data/lib/dcidev_mailer.rb CHANGED
@@ -18,20 +18,16 @@ module DcidevMailer
18
18
  def format_attachments(attachments)
19
19
  formatted = []
20
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
21
+ filetype = MimeMagic.by_magic(a[:file]).type.to_s
22
+ content = a[:file].read
23
+ name = "#{a[:filename]}.#{filetype.split("/")[1]}"
24
+ att = {
25
+ content: content,
26
+ name: name,
27
+ }
28
+
29
+ att[:type] = filetype if ENV["USE_MANDRILL_MAILER"].to_i == 0
30
+ formatted << att
35
31
  end
36
32
  formatted
37
33
  end
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.9
4
+ version: 0.0.13
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-17 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