mailpace-rails 0.3.2 → 0.4.1

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: 0e00e92354ac88a5a1ad8d1f2f8a35c513358b40768ee1bb78f15fdfdf56fc6b
4
- data.tar.gz: 886f86f439920c14262128adef015a7339c67d63a5e188d06872d6a9ba5d91d8
3
+ metadata.gz: e7ce7e73655598e9e849f7c5fae4c7f29252d42a2850531ee0c536c765ae9fcf
4
+ data.tar.gz: 825cdef3a2e02c9586341b7c916fd5a29ce74c7046d4ad6d19d601f2a73411f5
5
5
  SHA512:
6
- metadata.gz: 8f4733e58983c60e330627190116b508d4df6962165fedcf7ea3d3ddfd2772bbb3b176860cd02cdd2b627e00fb7c18404b9f1e545efb23c6f29ff4ff14ad5ed7
7
- data.tar.gz: e90bd2efb8b4cd34abe58cdc9f8bbd5d0fa7d6e27f18871fab6ca37f6d82bd1a409a3ac80ea35bed5271c408b61ce3f37ff9e25c1cdfbfbb3b3dd156e5ca2cbd
6
+ metadata.gz: bb6ff09788626e00abf53fe9f361df3f716afa7da25e758b819757a17b48d9d03493884c0807bdb61999baa6a57f7e24840ccdd2b07b1b31b381e4cf9fa995ef
7
+ data.tar.gz: ddce320b5a453eb67f6167069bb40ec6be315287fa833fcdac0dd603b3db69f97c22113a4775c7e795f07114f974cea0ee013653dc8c0dff7a9ce9e6eb566548
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
@@ -1,5 +1,5 @@
1
1
  module Mailpace
2
2
  module Rails
3
- VERSION = '0.3.2'
3
+ VERSION = '0.4.1'
4
4
  end
5
5
  end
@@ -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
@@ -40,7 +42,9 @@ module Mailpace
40
42
  'Accept' => 'application/json',
41
43
  'Content-Type' => 'application/json',
42
44
  'Mailpace-Server-Token' => settings[:api_token]
43
- }
45
+ }.tap do |h|
46
+ h['Idempotency-Key'] = mail.header['idempotency_key'].to_s if mail.header['idempotency_key']
47
+ end
44
48
  )
45
49
 
46
50
  handle_response(result)
@@ -63,9 +67,10 @@ module Mailpace
63
67
  def handle_response(result)
64
68
  return result unless result.code != 200
65
69
 
66
- # TODO: Improved error handling
67
- res = result.parsed_response
68
- raise res['error']&.to_s || res['errors']&.to_s
70
+ parsed_response = result.parsed_response
71
+ error_message = join_error_messages(parsed_response)
72
+
73
+ raise DeliveryError, "MAILPACE Error: #{error_message}" unless error_message.empty?
69
74
  end
70
75
 
71
76
  def format_attachments(attachments)
@@ -88,9 +93,15 @@ module Mailpace
88
93
  obj&.address_list
89
94
  end
90
95
  end
96
+
97
+ def join_error_messages(response)
98
+ # Join 'error' and 'errors' keys from response into a single string
99
+ [response['error'], response['errors']].compact.join(', ')
100
+ end
91
101
  end
92
102
 
93
103
  class Error < StandardError; end
104
+ class DeliveryError < StandardError; end
94
105
 
95
106
  def self.root
96
107
  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.3.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MailPace
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-23 00:00:00.000000000 Z
11
+ date: 2024-10-20 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.4.1
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.4.1
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.3.26
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: []