mailpy 0.1.6 → 0.1.7

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: 21476287a915391df402c2d12dd74a6665e594c1b5eec0a5e19d75f59544fc1e
4
- data.tar.gz: 49f4380a0e2d0ec8e7fb07063b7a969d46374ac332dfef8487066372a97e5e1b
3
+ metadata.gz: e8a89f05d3dd0d6875dd4721e7fddeb47932ea72bca76b29dba13426867f6caa
4
+ data.tar.gz: 25c5965f5b4938b48351dd43371cd0341512735cd83f9cd0579ed2f37c0051ae
5
5
  SHA512:
6
- metadata.gz: 3ca3d484f041f422d8c9d1b97102d3177e678ce5795014220237c9716f8b2fd099cab5d544928ec1cc57e43b93ca9171899a24a97894e6d1e45ab8f3c4055c09
7
- data.tar.gz: f09f2eae711235ab0320344db3e535c690844261f611be0cc7c600c8b556849ad6e0490025b31aaf0264b6e2725b1826d083820ea28958b8928cb9cf18e3b997
6
+ metadata.gz: 8d82d4ab3cdc74541b61357735c6c29f0cb7af8fa70aedfb745a4c4255ff2f935fb28879d9db3c0a4cebcd38dbf1f5d75a50149c1d401ea14ce00688aeeea6e7
7
+ data.tar.gz: 67b066c8a6d5587c88e50116c889f0bcf616c09673aa1a6ccb1e4fed52a02c30847885fbccf0485754ef0896b8eff5b57d7cc4054398220d9a94230c4ac8eeca
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,12 +15,24 @@ 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
22
  headers: {
21
23
  Authorization: ENV['MAILER_API_KEY_OR_AUTH_TOKEN']
22
24
  }
23
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'
35
+ }
24
36
  ```
25
37
 
26
38
  And then execute:
data/lib/mailpy.rb CHANGED
@@ -17,9 +17,16 @@ module Mailpy
17
17
 
18
18
  private
19
19
  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
20
+ begin
21
+ result = MailerApi.new(mail, settings).send
22
+ raise(MailpyDeliveryError, JSON.parse(result.body)['message']) unless result.code === 200
23
+ result
24
+ rescue Errno::ECONNREFUSED
25
+ smtp_settings = Rails.application.config.action_mailer.smtp_settings
26
+ raise(MailpyDeliveryError, "SMTP miss configured. Please add SMTP configuration in your environment config") if smtp_settings.blank?
27
+ result = SMTPApi.new(mail, smtp_settings).send
28
+ result
29
+ end
23
30
  end
24
31
  end
25
32
  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.6'
2
+ VERSION = '0.1.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nasrul Gunawan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-23 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -51,6 +51,7 @@ files:
51
51
  - lib/mailpy.rb
52
52
  - lib/mailpy/mailer_api.rb
53
53
  - lib/mailpy/railtie.rb
54
+ - lib/mailpy/smtp_api.rb
54
55
  - lib/mailpy/version.rb
55
56
  homepage: https://github.com/nasrulgunawan/mailpy
56
57
  licenses: