mailpy 0.1.4 → 0.1.9

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: 385d9f2c54a82f019dda1cd1a3b66ed094a7f87abe5d0d7d40bb88ee54e4f2bb
4
- data.tar.gz: '0796cd3016d2675fe446b0d2255c8359b35418ad3394646088d135c8c15109fc'
3
+ metadata.gz: 884c6b9c6c589b1051aafc31e6fb4c5542087546bbb96bc809a4474d3c20df5f
4
+ data.tar.gz: c45b331ac3d2da02e548289e6b76b8b095083f9036b8e0fbb9ca492045a8967a
5
5
  SHA512:
6
- metadata.gz: 854ae6892456083d68b93376d2a67ef075c49d3bd25957a6fc42f31a86e8281e233ba299212d368a2f2c9d400f03ced70e7a55d4bf5b5adc24c11f1e644f7521
7
- data.tar.gz: fe9811beccd2286a53f49277870ff9de6b70707248e324edc79a8b79589642119c4dc7e18ab6ef073374f5b3cb0391d137baf6839494076d37c01b9656ac74e6
6
+ metadata.gz: 100bcc0abe335079c3d68f750d5daa784f23a0273a11693179367e10bb58de1740056cb73bae89ad3100ce0feac0d24b445455c4ac7f70366a98056730bdfecd
7
+ data.tar.gz: 255bd5ef159e9a25946efc6796b67465a8d1043aac98c94eb9d917e5a1d8612f7e72c656be75841ecce9046de3950c7af009d985d610e833c664a21307481f67
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Mailpy
2
- Action Mailer Adapter for Send Email Through HTTP APIs.
2
+ Action Mailer Adapter for Sending Email Through HTTP APIs. Mailpy will automatically switch to SMTP method in case your mailer server encounter any problem.
3
3
 
4
4
  ## Usage
5
5
  How to use my plugin.
@@ -15,9 +15,23 @@ Add configuration to your application environments. development.rb, staging.rb,
15
15
 
16
16
  ```ruby
17
17
  config.action_mailer.delivery_method = :mailpy
18
+ config.action_mailer.perform_deliveries = true
19
+ config.action_mailer.raise_delivery_errors = true
18
20
  config.action_mailer.mailpy_settings = {
19
21
  endpoint: ENV['MAILER_API_ENDPOINT'],
20
- token: ENV['MAILER_API_KEY_OR_AUTH_TOKEN']
22
+ headers: {
23
+ Authorization: ENV['MAILER_API_KEY_OR_AUTH_TOKEN']
24
+ }
25
+ }
26
+ config.action_mailer.smtp_settings = {
27
+ address: ENV['SMTP_ADDRESS'],
28
+ port: ENV['SMTP_PORT'],
29
+ domain: ENV['SMTP_DOMAIN'],
30
+ authentication: ENV['SMTP_AUTHENTICATION_METHOD'],
31
+ user_name: ENV['SMTP_USERNAME'],
32
+ password: ENV['SMTP_PASSWORD'],
33
+ enable_starttls_auto: true,
34
+ openssl_verify_mode: 'none'
21
35
  }
22
36
  ```
23
37
 
data/lib/mailpy.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "mailpy/railtie"
2
2
  require "mailpy/mailer_api"
3
+ require "mailpy/smtp_api"
3
4
 
4
5
  module Mailpy
5
6
  class DeliveryMethod
@@ -17,9 +18,16 @@ module Mailpy
17
18
 
18
19
  private
19
20
  def perform_send_request(mail, settings)
20
- result = MailerApi.new(mail, settings).send
21
- raise(MailpyDeliveryError, JSON.parse(result.body)['message']) unless result.code === 200
22
- result
21
+ begin
22
+ result = MailerApi.new(mail, settings).send
23
+ raise(MailpyDeliveryError, JSON.parse(result.body)['message']) unless result.code === 200
24
+ result
25
+ rescue Errno::ECONNREFUSED
26
+ smtp_settings = Rails.application.config.action_mailer.smtp_settings
27
+ raise(MailpyDeliveryError, "SMTP miss configured. Please add SMTP configuration in your environment config") if smtp_settings.blank?
28
+ result = SMTPApi.new(mail, smtp_settings).send
29
+ result
30
+ end
23
31
  end
24
32
  end
25
33
  end
@@ -23,12 +23,24 @@ class MailerApi
23
23
  cc: mail.cc.try(:join, ', '),
24
24
  bcc: mail.bcc.try(:join, ', '),
25
25
  from: mail.from.try(:join, ', '),
26
+ options: eval(mail[:options].to_s),
26
27
  subject: mail.subject,
27
- body: mail.body.to_s
28
- }.to_json
28
+ body: body_data,
29
+ attachment: attachment_data
30
+ }
31
+ end
32
+
33
+ def body_data
34
+ mail.body.parts.present? ? mail.body.parts[0].body.to_s : mail.body.to_s
35
+ end
36
+
37
+ def attachment_data
38
+ attachments = {}
39
+ mail.attachments.each { |attachment| attachments[attachment.filename] = attachment.body }
40
+ attachments
29
41
  end
30
42
 
31
43
  def headers
32
- { 'Content-Type': 'application/json' }.merge!(options[:headers])
44
+ options[:headers]
33
45
  end
34
- end
46
+ end
@@ -0,0 +1,14 @@
1
+ class SMTPApi < ActionMailer::Base
2
+ def initialize(mail, options = {})
3
+ @mail = mail
4
+ @options = options
5
+ end
6
+
7
+ def send
8
+ mail.delivery_method :smtp, options
9
+ mail.deliver!
10
+ end
11
+
12
+ private
13
+ attr_reader :mail, :options
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Mailpy
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.9'
3
3
  end
metadata CHANGED
@@ -1,35 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nasrul Gunawan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 5.2.4
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 5.2.4.4
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: 5.2.4
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 5.2.4.4
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: httparty
35
15
  requirement: !ruby/object:Gem::Requirement
@@ -58,7 +38,7 @@ dependencies:
58
38
  - - ">="
59
39
  - !ruby/object:Gem::Version
60
40
  version: '0'
61
- description: Action Mailer Adapter for Send Email Through HTTP APIs.
41
+ description: Action Mailer Adapter for sending email through HTTP APIs.
62
42
  email:
63
43
  - nasrul.remaza@gmail.com
64
44
  executables: []
@@ -71,6 +51,7 @@ files:
71
51
  - lib/mailpy.rb
72
52
  - lib/mailpy/mailer_api.rb
73
53
  - lib/mailpy/railtie.rb
54
+ - lib/mailpy/smtp_api.rb
74
55
  - lib/mailpy/version.rb
75
56
  homepage: https://github.com/nasrulgunawan/mailpy
76
57
  licenses:
@@ -91,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
72
  - !ruby/object:Gem::Version
92
73
  version: '0'
93
74
  requirements: []
94
- rubygems_version: 3.0.8
75
+ rubygems_version: 3.0.3
95
76
  signing_key:
96
77
  specification_version: 4
97
78
  summary: Summary of Mailpy.