mailpy 0.1.3 → 0.1.8
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 +16 -2
- data/lib/mailpy.rb +15 -11
- data/lib/mailpy/mailer_api.rb +33 -22
- data/lib/mailpy/smtp_api.rb +14 -0
- data/lib/mailpy/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1107fdfa3e34f5a7f3facf3ec3c500fe235bf9df7fca0dcdfa0c736c80daa138
|
4
|
+
data.tar.gz: 1e487dead8d9daa50dfde103094cc2e1423e2a62fa7ee2d2d57c87f2bef32ba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e328e35fe23943fcd35eabbfda65754228e61f1a027bfc197d9c9826919d022dac1018cc63bce095872278e2d094f2092270f33c3847dbcb8af3bc4b4124cba5
|
7
|
+
data.tar.gz: 4a70ed84ef95657f698abc9100aa2b3ed816ac230f985ea91dc5c0c8df92696ce47521dfc2a7541cdb6320bfe136b2650a24099673415cc1463d23b94d2d5609
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Mailpy
|
2
|
-
Action Mailer Adapter for
|
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
|
-
|
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,8 +1,11 @@
|
|
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
|
7
|
+
MailpyDeliveryError = Class.new(StandardError)
|
8
|
+
|
6
9
|
attr_accessor :settings
|
7
10
|
|
8
11
|
def initialize(params)
|
@@ -10,20 +13,21 @@ module Mailpy
|
|
10
13
|
end
|
11
14
|
|
12
15
|
def deliver!(mail)
|
13
|
-
|
16
|
+
perform_send_request(mail, settings)
|
14
17
|
end
|
15
18
|
|
16
19
|
private
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def perform_send_request(mail, settings)
|
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
|
27
30
|
end
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
data/lib/mailpy/mailer_api.rb
CHANGED
@@ -1,34 +1,45 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
3
|
class MailerApi
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(options, message)
|
4
|
+
def initialize(mail, options = {})
|
5
|
+
@mail = mail
|
7
6
|
@options = options
|
8
|
-
@message = message
|
9
7
|
end
|
10
8
|
|
11
9
|
def send
|
12
|
-
|
10
|
+
result = HTTParty.post(
|
11
|
+
options[:endpoint],
|
12
|
+
body: form_data,
|
13
|
+
headers: headers
|
14
|
+
)
|
13
15
|
end
|
14
16
|
|
15
17
|
private
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
headers: {
|
29
|
-
'Content-Type': 'application/json',
|
30
|
-
'Authorization': options[:token].to_s
|
18
|
+
attr_reader :mail, :options
|
19
|
+
|
20
|
+
def form_data
|
21
|
+
{
|
22
|
+
to: mail.to.try(:join, ', '),
|
23
|
+
cc: mail.cc.try(:join, ', '),
|
24
|
+
bcc: mail.bcc.try(:join, ', '),
|
25
|
+
from: mail.from.try(:join, ', '),
|
26
|
+
subject: mail.subject,
|
27
|
+
body: body_data,
|
28
|
+
attachment: attachment_data
|
31
29
|
}
|
32
|
-
|
33
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
def body_data
|
33
|
+
mail.body.parts.present? ? mail.body.parts[0].body.to_s : mail.body.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def attachment_data
|
37
|
+
attachments = {}
|
38
|
+
mail.attachments.each { |attachment| attachments[attachment.filename] = attachment.body }
|
39
|
+
attachments
|
40
|
+
end
|
41
|
+
|
42
|
+
def headers
|
43
|
+
options[:headers]
|
44
|
+
end
|
34
45
|
end
|
data/lib/mailpy/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nasrul Gunawan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: Action Mailer Adapter for
|
41
|
+
description: Action Mailer Adapter for sending email through HTTP APIs.
|
42
42
|
email:
|
43
43
|
- nasrul.remaza@gmail.com
|
44
44
|
executables: []
|
@@ -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:
|
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
72
|
- !ruby/object:Gem::Version
|
72
73
|
version: '0'
|
73
74
|
requirements: []
|
74
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.1.4
|
75
76
|
signing_key:
|
76
77
|
specification_version: 4
|
77
78
|
summary: Summary of Mailpy.
|