dcidev_mailer 0.0.16 → 0.0.18
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 +39 -4
- data/lib/dcidev_mailer/mandrill.rb +7 -6
- data/lib/dcidev_mailer/mandrill_template.rb +5 -4
- data/lib/dcidev_mailer.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a307fb952b55347c9179dc189fb8985dc77e12dc2cd2da701101fa436c38a28c
|
4
|
+
data.tar.gz: e67cd65ca7997d4e1b325fcf9aca21b9f1aaa68d10bdd01ed15ebc9c04dc45c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e0fa773abcd440cb1cd8936a74349dd0bf0e89000dfcbdbcaff76c7776422f823e06910161e63058448e8483a880b86009f6cef8c920ca4aa13c3339b76a5bc
|
7
|
+
data.tar.gz: 841ac66e022fe389612eb49bbbf481eba8ae04b83b82a05c1d553c344c5f535b4264f25156363df14cb00a2d054eb020346d72090b38d3fad9c543762ac0bced
|
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
|
-
|
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:
|
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
|
-
locals, images = DcidevMailer.format_header_footer(header_url: header_url, footer_url: footer_url, locals: locals, images: images) if header_url.present?
|
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,8 +29,9 @@ 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
|
36
|
-
end
|
37
|
+
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
|
data/lib/dcidev_mailer.rb
CHANGED
@@ -43,7 +43,7 @@ module DcidevMailer
|
|
43
43
|
|
44
44
|
def format_header_footer(header_url: "", footer_url: "", locals: {}, images: {})
|
45
45
|
[{ name: "header", url: header_url }, { name: "footer", url: footer_url }].each do |i|
|
46
|
-
|
46
|
+
next if i[:url].nil?
|
47
47
|
begin
|
48
48
|
extension, encoded, _ = DcidevUtility.file_url_to_base64(i[:url])
|
49
49
|
locals[i[:name].to_sym] = "cid:#{i[:name]}"
|
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.18
|
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:
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mimemagic
|