konsierge-smtp-mailer 0.1.2 → 0.2.0

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: 6629397d002ace5df83f3a0cadc2340c2b8a25f895cbd9d7edf1762599a6317e
4
- data.tar.gz: ea204b983049f351a4bac90e6267d2c3bf0802a830e0dbbec9a06df494962f39
3
+ metadata.gz: 2609fe2e19c423d664e8ce2838f930d01c80baa4fed61bf08056c8f3f79e16f8
4
+ data.tar.gz: 6e0c02f5431153f314d395b942d7b23c67afe1536e4ef08bb1bf109b1382853d
5
5
  SHA512:
6
- metadata.gz: e16ae8699703197dfaf8b461cd0e5eda8261deff7f489f92d52f9bba44ad591f0ef7da89b9fdd76c90eb04a7f9436b5a8770f618e99f7b3febbf000b2c385101
7
- data.tar.gz: 61e95b24babcc2175c90fccc23f49478f9081b586207e31446914169e9cb0183206e76e223299c66725a3abc428b8901e35475b6a2346199ef07dc0a9c5a131d
6
+ metadata.gz: 4a828298487f2673b312732ba37c951de049ee231e759231d45bc80025d79a54b6010aad5bff97ff0c96e23a7f6f3c5cea8bc77a7096251db57ea6078d80943d
7
+ data.tar.gz: 3ddcf9af4d8d903aa2b896892b823f8c7380b00f9b82a7e578af08245b8f83c4f7ffeeda59447d284755d2b549716810d5e842036c8528f0a38e092f4fa77720
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
- ## [0.1.0] - 2021-11-01
1
+ ## [0.2.0] - 2021-11-03
2
+ - Added attachments support
3
+ - Improve body decoding
4
+
5
+ ## [0.1.2] - 2021-11-02
6
+ - Generator fixes
2
7
 
8
+ ## [0.1.1] - 2021-11-02
9
+ - Added generator
10
+
11
+ ## [0.1.0] - 2021-11-01
3
12
  - Initial release
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KonsiergeSmtpMailer
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -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); end
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: mail.body.to_s,
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
- RestClient.post(url, params.to_json, {
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.1.2
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-01 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer