dcidev_mailer 0.0.16 → 0.0.17

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: 3f3f6f2bc44b3d45a845f89bc2922dfb527a8a3fd98156b444a46fb1920ef355
4
- data.tar.gz: e395df17cc4a719004e7d58b513aaa8d534032c335b82e34054380c08fa427be
3
+ metadata.gz: 9f17117f9022e28dd492ea92310d25c16211f02a04376178027b069d1fc61ad1
4
+ data.tar.gz: fed2751d446175a98589df0e56bc22a7eb3181fab2bac922b35e3d63cd9fc285
5
5
  SHA512:
6
- metadata.gz: 26926484cb0021436d5a9f9d74a9927d3220f6bdea7438c9d6ba99ea104c21290fde491c60af8f413772e01df74e79cc12f6e8fa3c54d3879a7716caa9be83fd
7
- data.tar.gz: f82ebb6124f7425de9fc3b2b6bd8e09122f8514b3137dfb7e23ce31dfecf48e99c5e6dd5284f08aead7157ce8e0fce736b7445e9743c57589fe6377e16ab04a0
6
+ metadata.gz: a873c97823a43f7fe38e8bbde83e77f6061baaa443b91b9412594f59c9e75ce2a0ac78b07c2b72c307e08bd6fcfffc8e69df3141c53330ce2359f6ce4ad594c0
7
+ data.tar.gz: 2577fce86abfe175086a91e6d6e245a3aa4af91bd1e64b065f5470f4f6f8ec63138417aa91116353f9eaaf9df7a3e50ca062464b24448f4d1d5443d06e96d376
data/README.md CHANGED
@@ -3,7 +3,12 @@ This gem uses both Mandrill API and ActionMailer to send email.
3
3
 
4
4
  # Setup
5
5
 
6
- Add this to your `.env`
6
+ Install mandrill mailer gem
7
+ ```
8
+ gem 'mandrill_mailer'
9
+ ```
10
+
11
+ Add `.env` configurations
7
12
  ```env
8
13
  BASE_URL_FE=
9
14
  DEFAULT_EMAIL_SENDER=
@@ -163,11 +168,11 @@ class MortgageMailer
163
168
  header_url: template.header.try(:url),
164
169
  footer_url: template.footer.try(:url),
165
170
  file_attachments: file_attachments,
166
- to: customer.email,
171
+ to: "#{customer.name} <#{customer.email}>",
167
172
  cc: nil, # can be a string / array
168
- bcc: nil, # can be a string / array
173
+ bcc: ["John Doe <john.doe@gmail.com>", "Michael <michael@gmail.com>"], # can be a string / array
169
174
  subject: template.subject,
170
- from: ENV['DEFAULT_EMAIL_SENDER'],
175
+ from: "#{ENV['DEFAULT_EMAIL_SENDER_NAME']} <#{ENV['DEFAULT_EMAIL_SENDER']}>",
171
176
  template_path: "mail/blast.html.erb" # specify template file location
172
177
  ).deliver_now!
173
178
  rescue => e
@@ -187,6 +192,36 @@ The attachment is an array of hashes containing attachment file and filename
187
192
  attachments = [{file: DcidevUtility.download_to_file(self.ktp.url), filename: self.reference_number}]
188
193
  ```
189
194
 
195
+ ### Inline Images
196
+ `MandrillMailer` supports sending images in the html body. As for `RailsMailer`, it currently only supports header & footer image. Feel free to contact me if you need such feature.
197
+
198
+ Since gmail do not support link-based image, you have to format the images as inline attachments and use CID (Content-ID) to display each of them. The gem automatically takes care of the programming. You only have to specify a valid link as the parameter.
199
+
200
+ The example to set the image in the template is shown below. This method works for both `RailsMailer` and `MandrillMailer` so you only need to code once.
201
+ ```html
202
+ <%
203
+ header = attachments['header'].try(:url) || header
204
+ footer = attachments['footer'].try(:url) || footer
205
+ %>
206
+
207
+ <% if header.present? %>
208
+ <div id="header-section-img">
209
+
210
+ <img
211
+ src="<%= header %>"
212
+ alt="Header Image"
213
+ style="border-radius: 10px"
214
+ width="100%"
215
+ />
216
+
217
+ </div>
218
+ <% end %>
219
+ ```
220
+
221
+ ### Development tips for custom SMTP server
222
+ Some clients dont allow our server to access their SMTP server. To avoid blind coding, you can develop using google SMTP server to make sure that your program woks perfectly.
223
+ Refer to https://dev.to/morinoko/sending-emails-in-rails-with-action-mailer-and-gmail-35g4 for the tutorial.
224
+
190
225
  ### Helpers
191
226
  ```ruby
192
227
  # convert all image URL in <img src="url"> to <img src="cid:xxxx">
@@ -5,17 +5,17 @@ module DcidevMailer
5
5
  default from: ENV['DEFAULT_EMAIL_SENDER']
6
6
 
7
7
  class << self
8
- def send_email(subject: '', html_body: '', to: nil, cc: nil, bcc: nil, from: nil, from_name: 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, from_name: nil, attachments: nil, email_template_path: '', header_url: '', footer_url: '', preserve_recipients: false)
9
9
  ac = ActionController::Base.new
10
10
  wording, images = DcidevMailer.format_image_from_html(html_body)
11
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, cc, bcc, html_body, attachments, images, from, from_name).deliver_now
15
+ self.send_mail(subject, to, cc, bcc, html_body, attachments, images, from, from_name, preserve_recipients).deliver_now
16
16
  end
17
17
 
18
- def send_mail(subject, to, cc, bcc, html, attachments = nil, images = nil, from = nil, from_name = nil)
18
+ def send_mail(subject, to, cc, bcc, html, attachments = nil, images = nil, from = nil, from_name = nil, preserve_recipients)
19
19
  mandrill_mail subject: subject,
20
20
  from: from,
21
21
  from_name: from_name,
@@ -29,7 +29,8 @@ module DcidevMailer
29
29
  important: true,
30
30
  inline_css: true,
31
31
  attachments: attachments,
32
- images: images
32
+ images: images,
33
+ preserve_recipients: cc.present? || preserve_recipients
33
34
  end
34
35
  end
35
36
  end
@@ -5,14 +5,14 @@ module DcidevMailer
5
5
  default from: ENV['DEFAULT_EMAIL_SENDER']
6
6
 
7
7
  class << self
8
- def send_email(subject: '', to: nil, cc: nil, bcc: nil, from: nil, from_name: nil, attachments: nil, vars: nil, template_name: nil, images: nil)
8
+ def send_email(subject: '', to: nil, cc: nil, bcc: nil, from: nil, from_name: nil, attachments: nil, vars: nil, template_name: nil, images: nil, preserve_recipients: false)
9
9
  raise DcidevMailer::Errors::InvalidTemplate unless template_name.present?
10
10
  images = DcidevMailer.format_images(images) if images.present?
11
11
  attachments = DcidevMailer.format_attachments(attachments) if attachments.present?
12
- self.send_mail(subject, to, cc, bcc, attachments, images, from, from_name, template_name, vars).deliver_now
12
+ self.send_mail(subject, to, cc, bcc, attachments, images, from, from_name, template_name, vars, preserve_recipients).deliver_now
13
13
  end
14
14
 
15
- def send_mail(subject, to, cc, bcc, attachments = nil, images = nil, from = nil, from_name = nil, template_name = nil, vars = nil)
15
+ def send_mail(subject, to, cc, bcc, attachments = nil, images = nil, from = nil, from_name = nil, template_name = nil, vars = nil, preserve_recipients)
16
16
  mandrill_mail subject: subject,
17
17
  from: from,
18
18
  from_name: from_name,
@@ -24,7 +24,8 @@ module DcidevMailer
24
24
  attachments: attachments,
25
25
  images: images,
26
26
  template_name: template_name,
27
- vars: vars
27
+ vars: vars,
28
+ preserve_recipients: cc.present? || preserve_recipients
28
29
  end
29
30
  end
30
31
  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.16
4
+ version: 0.0.17
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-04-19 00:00:00.000000000 Z
11
+ date: 2022-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mimemagic
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.0.3.1
74
+ rubygems_version: 3.1.2
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Commonly used email codes