konsierge-smtp-mailer 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/lib/konsierge-smtp-mailer/version.rb +1 -1
- data/lib/konsierge-smtp-mailer.rb +30 -9
- 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: 2609fe2e19c423d664e8ce2838f930d01c80baa4fed61bf08056c8f3f79e16f8
|
4
|
+
data.tar.gz: 6e0c02f5431153f314d395b942d7b23c67afe1536e4ef08bb1bf109b1382853d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a828298487f2673b312732ba37c951de049ee231e759231d45bc80025d79a54b6010aad5bff97ff0c96e23a7f6f3c5cea8bc77a7096251db57ea6078d80943d
|
7
|
+
data.tar.gz: 3ddcf9af4d8d903aa2b896892b823f8c7380b00f9b82a7e578af08245b8f83c4f7ffeeda59447d284755d2b549716810d5e842036c8528f0a38e092f4fa77720
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'konsierge-smtp-mailer/version'
|
4
4
|
require_relative 'konsierge-smtp-mailer/config'
|
5
|
+
require 'fileutils'
|
5
6
|
|
6
7
|
module KonsiergeSmtpMailer
|
7
8
|
class ConfigError < StandardError; end
|
@@ -9,23 +10,41 @@ module KonsiergeSmtpMailer
|
|
9
10
|
|
10
11
|
class Mailer
|
11
12
|
|
12
|
-
def initialize(*args)
|
13
|
-
|
14
|
-
def deliver!(mail)
|
15
|
-
|
13
|
+
def initialize(*args)
|
16
14
|
if KonsiergeSmtpMailer.config.smtp_mailer_host.nil? or KonsiergeSmtpMailer.config.smtp_mailer_auth_key.nil?
|
17
15
|
raise ConfigError.new('Please provide config in initializers/konsierge-smtp-mailer.rb')
|
18
16
|
end
|
17
|
+
@temp_dir = "./tmp/konsierge-smtp-mailer/#{SecureRandom.uuid}/"
|
18
|
+
@url = "#{KonsiergeSmtpMailer.config.smtp_mailer_host}/v1/message"
|
19
|
+
end
|
20
|
+
|
21
|
+
def deliver!(mail)
|
19
22
|
|
20
|
-
url = "#{KonsiergeSmtpMailer.config.smtp_mailer_host}/v1/message"
|
21
23
|
params = {
|
22
24
|
subject: mail.subject,
|
23
|
-
body:
|
25
|
+
body: '',
|
24
26
|
recipients: mail.to.as_json,
|
25
27
|
cc: mail.cc.as_json,
|
26
|
-
bcc: mail.bcc.as_json
|
28
|
+
bcc: mail.bcc.as_json,
|
29
|
+
attachments: []
|
27
30
|
}
|
28
|
-
|
31
|
+
|
32
|
+
if mail.text_part.present?
|
33
|
+
params[:body] = mail.text_part.decode_body
|
34
|
+
elsif mail.html_part.present?
|
35
|
+
params[:body] = mail.html_part.decode_body
|
36
|
+
end
|
37
|
+
|
38
|
+
if mail.attachments.present?
|
39
|
+
FileUtils.mkdir_p @temp_dir unless File.exist? @temp_dir
|
40
|
+
mail.attachments.each do |attachment|
|
41
|
+
tmp_path = "#{@temp_dir}#{attachment.filename}"
|
42
|
+
File.open(tmp_path, 'wb') { |f| f.write(attachment.read) }
|
43
|
+
params[:attachments] << File.open(tmp_path, 'rb')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
RestClient.post(@url, params.to_json, {
|
29
48
|
Authorization: "Basic #{KonsiergeSmtpMailer.config.smtp_mailer_auth_key}",
|
30
49
|
content_type: :json,
|
31
50
|
accept: :json
|
@@ -33,7 +52,9 @@ module KonsiergeSmtpMailer
|
|
33
52
|
|
34
53
|
rescue => e
|
35
54
|
raise MailerError.new(e.message)
|
55
|
+
ensure
|
56
|
+
FileUtils.rm_rf(@temp_dir) if File.exist? @temp_dir
|
36
57
|
end
|
37
|
-
end
|
38
58
|
|
59
|
+
end
|
39
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: konsierge-smtp-mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Digital Box Mobile
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|