mailpace-rails 0.3.2 → 0.4.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 +4 -4
- data/README.md +22 -0
- data/lib/mailpace-rails/version.rb +1 -1
- data/lib/mailpace-rails.rb +14 -4
- metadata +36 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 116f3c2d1a6a94ee97b33eccd6b576ffa86146e262fa18fea458fd30cc6ce9bb
|
4
|
+
data.tar.gz: 367ca296eff427a12a36a56096a04ebc0e694f635d9667c629db4b67c67f65bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c93b6b5261b781d2692f76732deea6940ab615229cb548986d44023245e5426fdb98937a046cb7dc7f57b5f3c14301107784b22aca641f6c5e10fc1c4ae3467
|
7
|
+
data.tar.gz: 9a4e461785290e63f2bced09602a6c9770ca747d120ba8ac1247d9fc7a792bf91347f74ef759473604baefdb46cdaf9a9cf56c351ba8e6b4d87b1db97d9c09ce
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
The MailPace Rails Gem is a plug in for ActionMailer to send emails via [MailPace](https://mailpace.com) to make sending emails from Rails apps super simple.
|
10
10
|
|
11
|
+
> **New in 0.4.0: [Idempotent Requests](https://docs.mailpace.com/guide/idempotency/), Improved Error Handling, InReplyTo and References support**
|
12
|
+
|
11
13
|
> **New in 0.3.0: The ability to consume [inbound emails](https://docs.mailpace.com/guide/inbound/) from MailPace via ActionMailbox**
|
12
14
|
|
13
15
|
## Usage
|
@@ -133,6 +135,26 @@ Alternatively, provide the password in the `RAILS_INBOUND_EMAIL_PASSWORD` enviro
|
|
133
135
|
`https://actionmailbox:PASSWORD@example.com/rails/action_mailbox/mailpace/inbound_emails`
|
134
136
|
|
135
137
|
That's it! Emails should start flowing into your app just like magic.
|
138
|
+
|
139
|
+
## Idempotent Requests
|
140
|
+
|
141
|
+
Mailpace supports [idempotency](https://docs.mailpace.com/guide/idempotency) for safely retrying requests without accidentally sending the same email twice. This is useful to guarantee that an email is not sent to the same recipient multiple times, e.g. through a network error, or a bug in your application logic.
|
142
|
+
|
143
|
+
To do this, when writing your mailer, generate and add a unique `idempotency_key`:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
class TestMailer < ApplicationMailer
|
147
|
+
default from: 'notifications@example.com'
|
148
|
+
def idempotent_mail
|
149
|
+
email = 'email@example.com'
|
150
|
+
mail(
|
151
|
+
to: email,
|
152
|
+
idempotency_key: Digest::SHA256.hexdigest("#{email}-#{Time.now.to_i / 3600}")
|
153
|
+
)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
136
158
|
## Support
|
137
159
|
|
138
160
|
For support please check the [MailPace Documentation](https://docs.mailpace.com) or contact us at support@mailpace.com
|
data/lib/mailpace-rails.rb
CHANGED
@@ -31,6 +31,8 @@ module Mailpace
|
|
31
31
|
cc: address_list(mail.header[:cc])&.addresses&.join(','),
|
32
32
|
bcc: address_list(mail.header[:bcc])&.addresses&.join(','),
|
33
33
|
replyto: mail.reply_to&.join(','),
|
34
|
+
inreplyto: mail.header['In-Reply-To'].to_s,
|
35
|
+
references: mail.header['References'].to_s,
|
34
36
|
list_unsubscribe: mail.header['list_unsubscribe'].to_s,
|
35
37
|
attachments: format_attachments(mail.attachments),
|
36
38
|
tags: mail.header['tags'].to_s
|
@@ -39,7 +41,8 @@ module Mailpace
|
|
39
41
|
'User-Agent' => "MailPace Rails Gem v#{Mailpace::Rails::VERSION}",
|
40
42
|
'Accept' => 'application/json',
|
41
43
|
'Content-Type' => 'application/json',
|
42
|
-
'Mailpace-Server-Token' => settings[:api_token]
|
44
|
+
'Mailpace-Server-Token' => settings[:api_token],
|
45
|
+
'Idempotency-Key' => mail.header['idempotency_key'].to_s
|
43
46
|
}
|
44
47
|
)
|
45
48
|
|
@@ -63,9 +66,10 @@ module Mailpace
|
|
63
66
|
def handle_response(result)
|
64
67
|
return result unless result.code != 200
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
parsed_response = result.parsed_response
|
70
|
+
error_message = join_error_messages(parsed_response)
|
71
|
+
|
72
|
+
raise DeliveryError, "MAILPACE Error: #{error_message}" unless error_message.empty?
|
69
73
|
end
|
70
74
|
|
71
75
|
def format_attachments(attachments)
|
@@ -88,9 +92,15 @@ module Mailpace
|
|
88
92
|
obj&.address_list
|
89
93
|
end
|
90
94
|
end
|
95
|
+
|
96
|
+
def join_error_messages(response)
|
97
|
+
# Join 'error' and 'errors' keys from response into a single string
|
98
|
+
[response['error'], response['errors']].compact.join(', ')
|
99
|
+
end
|
91
100
|
end
|
92
101
|
|
93
102
|
class Error < StandardError; end
|
103
|
+
class DeliveryError < StandardError; end
|
94
104
|
|
95
105
|
def self.root
|
96
106
|
Pathname.new(File.expand_path(File.join(__dir__, '..')))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailpace-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MailPace
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionmailbox
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activestorage
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 6.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 6.0.0
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: httparty
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +72,14 @@ dependencies:
|
|
44
72
|
requirements:
|
45
73
|
- - ">="
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version: 7.0
|
75
|
+
version: 7.2.0
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
80
|
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version: 7.0
|
82
|
+
version: 7.2.0
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: sqlite3
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,7 +116,7 @@ licenses:
|
|
88
116
|
metadata:
|
89
117
|
source_code_uri: https://github.com/mailpace/mailpace-rails
|
90
118
|
changelog_uri: https://github.com/mailpace/mailpace-rails/blob/master/CHANGELOG.md
|
91
|
-
post_install_message:
|
119
|
+
post_install_message:
|
92
120
|
rdoc_options: []
|
93
121
|
require_paths:
|
94
122
|
- lib
|
@@ -103,8 +131,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
131
|
- !ruby/object:Gem::Version
|
104
132
|
version: '0'
|
105
133
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
107
|
-
signing_key:
|
134
|
+
rubygems_version: 3.5.16
|
135
|
+
signing_key:
|
108
136
|
specification_version: 4
|
109
137
|
summary: Lets you send transactional emails from your app over an easy to use API
|
110
138
|
test_files: []
|