mailtrap 2.19.0 → 2.20.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 +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/README.md +41 -7
- data/lib/mailtrap/account_accesses_api.rb +2 -2
- data/lib/mailtrap/action_mailer/delivery_method.rb +13 -2
- data/lib/mailtrap/base_api.rb +6 -0
- data/lib/mailtrap/billing_usage.rb +1 -1
- data/lib/mailtrap/client.rb +23 -9
- data/lib/mailtrap/company_info.rb +1 -1
- data/lib/mailtrap/company_info_api.rb +14 -14
- data/lib/mailtrap/deprecation.rb +37 -0
- data/lib/mailtrap/domain.rb +48 -0
- data/lib/mailtrap/domains_api.rb +88 -0
- data/lib/mailtrap/email_campaign.rb +3 -3
- data/lib/mailtrap/email_campaigns_api.rb +4 -4
- data/lib/mailtrap/email_log_message.rb +1 -1
- data/lib/mailtrap/inbound_inbox.rb +1 -1
- data/lib/mailtrap/inbox.rb +5 -53
- data/lib/mailtrap/inboxes_api.rb +7 -108
- data/lib/mailtrap/marketing_stats_api.rb +1 -1
- data/lib/mailtrap/project.rb +1 -1
- data/lib/mailtrap/projects_api.rb +2 -2
- data/lib/mailtrap/sandbox.rb +57 -0
- data/lib/mailtrap/sandbox_attachments_api.rb +15 -7
- data/lib/mailtrap/sandbox_message.rb +1 -1
- data/lib/mailtrap/sandbox_messages_api.rb +16 -8
- data/lib/mailtrap/sandboxes_api.rb +117 -0
- data/lib/mailtrap/sending_domain.rb +5 -44
- data/lib/mailtrap/sending_domains_api.rb +7 -80
- data/lib/mailtrap/stats_api.rb +5 -5
- data/lib/mailtrap/sub_accounts_api.rb +13 -0
- data/lib/mailtrap/tracking_opt_out.rb +1 -1
- data/lib/mailtrap/tracking_opt_outs_api.rb +2 -2
- data/lib/mailtrap/version.rb +1 -1
- data/lib/mailtrap/webhook.rb +1 -1
- data/lib/mailtrap/webhooks_api.rb +1 -1
- data/lib/mailtrap.rb +2 -0
- metadata +7 -3
- data/mailtrap.gemspec +0 -34
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2ccfd5b379b9f377af4db48ea2f44530b380c85790cca4075bb80f5423ea3a7c
|
|
4
|
+
data.tar.gz: 27a7c8b0eb809f14f9d15a16ab87edd61537089e540424b35bbf0cb8695ec693
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 19b75f13c8ac894fa74e568ff0158032be8a423ad9d57c436f5528bd2456f044d69eb4a32ca95c133b79698bb68b5a242eb73271991a420910ac8c6695435b98
|
|
7
|
+
data.tar.gz: c61bf452c57c9e6b0d23415ebbe925f45c8fbb6a3053bee02f1201a1c53024451291339265e54c1eaf6020935cee36d20ff3a106e1892e7ad700b86977828c93
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## [2.20.1] - 2026-11-12
|
|
2
|
+
|
|
3
|
+
## What's Changed
|
|
4
|
+
* Add release workflow by @IgorDobryn in https://github.com/mailtrap/mailtrap-ruby/pull/141
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
**Full Changelog**: https://github.com/mailtrap/mailtrap-ruby/compare/v2.20.0...v2.20.1
|
|
8
|
+
|
|
9
|
+
## [2.20.0] - 2026-11-09
|
|
10
|
+
|
|
11
|
+
## What's Changed
|
|
12
|
+
* add sub account deletion by @oshchyhol in https://github.com/mailtrap/mailtrap-ruby/pull/130
|
|
13
|
+
* Add Sandbox and Domain names; deprecate the Inbox and SendingDomain names by @Rabsztok in https://github.com/mailtrap/mailtrap-ruby/pull/139
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
**Full Changelog**: https://github.com/mailtrap/mailtrap-ruby/compare/v2.19.0...v2.20.0
|
|
17
|
+
|
|
1
18
|
## [2.19.0] - 2026-10-29
|
|
2
19
|
|
|
3
20
|
## What's Changed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -115,7 +115,7 @@ Send emails to your Sandbox for testing purposes:
|
|
|
115
115
|
```ruby
|
|
116
116
|
require 'mailtrap'
|
|
117
117
|
|
|
118
|
-
client = Mailtrap::Client.new(api_key: 'your-api-key', sandbox: true,
|
|
118
|
+
client = Mailtrap::Client.new(api_key: 'your-api-key', sandbox: true, sandbox_id: YOUR_SANDBOX_ID)
|
|
119
119
|
client.send(mail)
|
|
120
120
|
|
|
121
121
|
# You can also pass the request parameters directly
|
|
@@ -139,9 +139,8 @@ Meaning your recipients will receive emails only in the default encoding which
|
|
|
139
139
|
is `quoted-printable`, if you send with Mailtrap API.
|
|
140
140
|
|
|
141
141
|
For those who need to use `7bit` or any other encoding, SMTP provides
|
|
142
|
-
better flexibility in that regard. Go to your _Mailtrap account_ →
|
|
143
|
-
→
|
|
144
|
-
configuration example.
|
|
142
|
+
better flexibility in that regard. Go to your _Mailtrap account_ → _Domains_
|
|
143
|
+
→ _Your domain_ → _Integration_ to find the SMTP configuration example.
|
|
145
144
|
|
|
146
145
|
### Multiple Mailtrap Clients
|
|
147
146
|
|
|
@@ -175,17 +174,17 @@ Email API:
|
|
|
175
174
|
|
|
176
175
|
- Full Email Sending – [`full.rb`](examples/full.rb)
|
|
177
176
|
- Batch Sending – [`batch.rb`](examples/batch.rb)
|
|
178
|
-
-
|
|
177
|
+
- Domains API – [`domains_api.rb`](examples/domains_api.rb)
|
|
179
178
|
- Sending Stats API – [`stats_api.rb`](examples/stats_api.rb)
|
|
180
179
|
- Email Logs API – [`email_logs_api.rb`](examples/email_logs_api.rb)
|
|
181
180
|
- Webhooks API – [`webhooks_api.rb`](examples/webhooks_api.rb)
|
|
182
181
|
- Suppressions API – [`suppressions_api.rb`](examples/suppressions_api.rb)
|
|
183
182
|
- Tracking Opt-outs API – [`tracking_opt_outs_api.rb`](examples/tracking_opt_outs_api.rb)
|
|
184
183
|
|
|
185
|
-
Email Sandbox
|
|
184
|
+
Email Sandbox:
|
|
186
185
|
|
|
187
186
|
- Projects CRUD – [`projects_api.rb`](examples/projects_api.rb)
|
|
188
|
-
-
|
|
187
|
+
- Sandboxes CRUD - [`sandboxes_api.rb`](examples/sandboxes_api.rb)
|
|
189
188
|
- Sandbox Messages CRUD - [`sandbox_messages_api.rb`](examples/sandbox_messages_api.rb)
|
|
190
189
|
- Sandbox Attachments API - [`sandbox_attachments_api.rb`](examples/sandbox_attachments_api.rb)
|
|
191
190
|
|
|
@@ -213,11 +212,46 @@ General:
|
|
|
213
212
|
- API Tokens API – [`api_tokens_api.rb`](examples/api_tokens_api.rb)
|
|
214
213
|
- Billing API – [`billing_api.rb`](examples/billing_api.rb)
|
|
215
214
|
- Permissions API – [`permissions_api.rb`](examples/permissions_api.rb)
|
|
215
|
+
- Sub Accounts API (list, create, delete) – [`sub_accounts_api.rb`](examples/sub_accounts_api.rb)
|
|
216
216
|
- Templates API (experimental) – [`templates_api.rb`](examples/templates_api.rb)
|
|
217
217
|
- Email Templates API – [`email_templates_api.rb`](examples/email_templates_api.rb)
|
|
218
218
|
- Action Mailer – [`action_mailer.rb`](examples/action_mailer.rb)
|
|
219
219
|
- Verifying webhook signatures – [`webhooks_signature_verification.ru`](examples/webhooks_signature_verification.ru)
|
|
220
220
|
|
|
221
|
+
## Renamed APIs
|
|
222
|
+
|
|
223
|
+
Email Sandbox inboxes are now called sandboxes, and sending domains are now called
|
|
224
|
+
domains. The old names still work and call the same API endpoints, but they print a
|
|
225
|
+
deprecation warning and will be removed in a future major release.
|
|
226
|
+
|
|
227
|
+
| Deprecated | Use instead |
|
|
228
|
+
|------------|-------------|
|
|
229
|
+
| `Mailtrap::InboxesAPI` | `Mailtrap::SandboxesAPI` |
|
|
230
|
+
| `Mailtrap::Inbox` | `Mailtrap::Sandbox` |
|
|
231
|
+
| `Mailtrap::SendingDomainsAPI` | `Mailtrap::DomainsAPI` |
|
|
232
|
+
| `Mailtrap::SendingDomain` | `Mailtrap::Domain` |
|
|
233
|
+
| `Mailtrap::Client.new(inbox_id:)` and the ActionMailer `inbox_id` setting | `sandbox_id` |
|
|
234
|
+
| `#inbox_id` on `Client`, `SandboxMessagesAPI` and `SandboxAttachmentsAPI` | `#sandbox_id` |
|
|
235
|
+
|
|
236
|
+
The other old names warn once per process. `Mailtrap::Inbox` and `Mailtrap::SendingDomain`
|
|
237
|
+
use Ruby's `deprecate_constant`, so they warn only when Ruby's deprecation warnings are
|
|
238
|
+
enabled (for example, `ruby -W:deprecated`), and they can warn more than once. Attributes and filters that
|
|
239
|
+
mirror API fields keep their names, such as `SandboxMessage#inbox_id`, `Project#inboxes`
|
|
240
|
+
and the `sending_domain_ids:` stats filter.
|
|
241
|
+
|
|
242
|
+
The once-per-process warnings print whether or not Ruby's deprecation warnings are
|
|
243
|
+
enabled, so `-W:no-deprecated` doesn't hide them. To silence them, filter out the
|
|
244
|
+
warnings tagged `[mailtrap]`:
|
|
245
|
+
|
|
246
|
+
```ruby
|
|
247
|
+
module SilenceMailtrapDeprecations
|
|
248
|
+
def warn(message, ...)
|
|
249
|
+
super unless message.include?('[mailtrap]')
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
Warning.extend(SilenceMailtrapDeprecations)
|
|
253
|
+
```
|
|
254
|
+
|
|
221
255
|
## Migration guide v1 → v2
|
|
222
256
|
|
|
223
257
|
Change `Mailtrap::Sending::Client` to `Mailtrap::Client`.
|
|
@@ -9,9 +9,9 @@ module Mailtrap
|
|
|
9
9
|
|
|
10
10
|
self.response_class = AccountAccess
|
|
11
11
|
|
|
12
|
-
# Retrieves a list of account accesses with optional filtering by domain,
|
|
12
|
+
# Retrieves a list of account accesses with optional filtering by domain, sandbox, or project IDs
|
|
13
13
|
# @param domain_ids [Array<Integer>] Optional array of domain IDs to filter by
|
|
14
|
-
# @param inbox_ids [Array<Integer>] Optional array of
|
|
14
|
+
# @param inbox_ids [Array<Integer>] Optional array of sandbox IDs to filter by
|
|
15
15
|
# @param project_ids [Array<Integer>] Optional array of project IDs to filter by
|
|
16
16
|
# @return [Array<AccountAccess>] List of account access objects
|
|
17
17
|
# @!macro api_errors
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative '../deprecation'
|
|
4
|
+
|
|
3
5
|
module Mailtrap
|
|
4
6
|
module ActionMailer
|
|
5
7
|
class DeliveryMethod
|
|
6
8
|
attr_accessor :settings
|
|
7
9
|
|
|
8
|
-
ALLOWED_PARAMS = %i[api_key api_host api_port bulk sandbox
|
|
10
|
+
ALLOWED_PARAMS = %i[api_key api_host api_port bulk sandbox sandbox_id].freeze
|
|
9
11
|
|
|
10
12
|
def initialize(settings)
|
|
11
13
|
self.settings = settings
|
|
@@ -22,7 +24,16 @@ module Mailtrap
|
|
|
22
24
|
private
|
|
23
25
|
|
|
24
26
|
def client
|
|
25
|
-
@client ||= Mailtrap::Client.new(**
|
|
27
|
+
@client ||= Mailtrap::Client.new(**client_settings)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def client_settings
|
|
31
|
+
params = settings.slice(*ALLOWED_PARAMS)
|
|
32
|
+
inbox_id = settings[:inbox_id]
|
|
33
|
+
return params if inbox_id.nil?
|
|
34
|
+
|
|
35
|
+
Deprecation.warn('The ActionMailer mailtrap_settings inbox_id', 'sandbox_id')
|
|
36
|
+
params.merge(sandbox_id: Deprecation.resolve_sandbox_id(params[:sandbox_id], inbox_id))
|
|
26
37
|
end
|
|
27
38
|
end
|
|
28
39
|
end
|
data/lib/mailtrap/base_api.rb
CHANGED
|
@@ -10,6 +10,12 @@ module Mailtrap
|
|
|
10
10
|
|
|
11
11
|
module ClassMethods
|
|
12
12
|
attr_accessor :supported_options, :response_class
|
|
13
|
+
|
|
14
|
+
def inherited(subclass)
|
|
15
|
+
super
|
|
16
|
+
subclass.supported_options = supported_options
|
|
17
|
+
subclass.response_class = response_class
|
|
18
|
+
end
|
|
13
19
|
end
|
|
14
20
|
|
|
15
21
|
# @param account_id [Integer] The account ID
|
|
@@ -4,7 +4,7 @@ module Mailtrap
|
|
|
4
4
|
# Data Transfer Object for Billing Usage data
|
|
5
5
|
# @see https://docs.mailtrap.io/developers/account-management/billing
|
|
6
6
|
# @attr_reader billing [Hash] The billing cycle details
|
|
7
|
-
# @attr_reader testing [Hash]
|
|
7
|
+
# @attr_reader testing [Hash] Email Sandbox subscription usage
|
|
8
8
|
# @attr_reader sending [Hash] Sending subscription usage
|
|
9
9
|
#
|
|
10
10
|
BillingUsage = Struct.new(
|
data/lib/mailtrap/client.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'net/http'
|
|
5
5
|
require 'uri'
|
|
6
|
+
require_relative 'deprecation'
|
|
6
7
|
|
|
7
8
|
module Mailtrap
|
|
8
9
|
class Client
|
|
@@ -12,7 +13,7 @@ module Mailtrap
|
|
|
12
13
|
GENERAL_API_HOST = 'mailtrap.io'
|
|
13
14
|
API_PORT = 443
|
|
14
15
|
|
|
15
|
-
attr_reader :api_key, :api_host, :general_api_host, :api_port, :bulk, :sandbox, :
|
|
16
|
+
attr_reader :api_key, :api_host, :general_api_host, :api_port, :bulk, :sandbox, :sandbox_id
|
|
16
17
|
|
|
17
18
|
# Initializes a new Mailtrap::Client instance.
|
|
18
19
|
#
|
|
@@ -25,8 +26,9 @@ module Mailtrap
|
|
|
25
26
|
# If enabled, it is incompatible with `sandbox: true`.
|
|
26
27
|
# @param [Boolean] sandbox Whether to use the Mailtrap sandbox API. Default: false.
|
|
27
28
|
# If enabled, it is incompatible with `bulk: true`.
|
|
28
|
-
# @param [Integer]
|
|
29
|
-
# @
|
|
29
|
+
# @param [Integer] sandbox_id The sandbox ID to send to. Required if sandbox API is used.
|
|
30
|
+
# @param [Integer] inbox_id Deprecated: use `sandbox_id` instead.
|
|
31
|
+
# @raise [ArgumentError] If api_key or api_port is nil, or if sandbox is true but sandbox_id is nil,
|
|
30
32
|
# or if incompatible options are provided.
|
|
31
33
|
def initialize( # rubocop:disable Metrics/ParameterLists
|
|
32
34
|
api_key: ENV.fetch('MAILTRAP_API_KEY'),
|
|
@@ -35,9 +37,14 @@ module Mailtrap
|
|
|
35
37
|
api_port: API_PORT,
|
|
36
38
|
bulk: false,
|
|
37
39
|
sandbox: false,
|
|
40
|
+
sandbox_id: nil,
|
|
38
41
|
inbox_id: nil
|
|
39
42
|
)
|
|
40
|
-
|
|
43
|
+
unless inbox_id.nil?
|
|
44
|
+
Deprecation.warn('Mailtrap::Client.new(inbox_id:)', 'Mailtrap::Client.new(sandbox_id:)')
|
|
45
|
+
sandbox_id = Deprecation.resolve_sandbox_id(sandbox_id, inbox_id)
|
|
46
|
+
end
|
|
47
|
+
validate_args!(api_key, api_port, bulk, sandbox, sandbox_id)
|
|
41
48
|
|
|
42
49
|
api_host ||= select_api_host(bulk:, sandbox:)
|
|
43
50
|
|
|
@@ -47,10 +54,17 @@ module Mailtrap
|
|
|
47
54
|
@api_port = api_port
|
|
48
55
|
@bulk = bulk
|
|
49
56
|
@sandbox = sandbox
|
|
50
|
-
@
|
|
57
|
+
@sandbox_id = sandbox_id
|
|
51
58
|
@http_clients = {}
|
|
52
59
|
end
|
|
53
60
|
|
|
61
|
+
# @deprecated Use {#sandbox_id} instead.
|
|
62
|
+
# @return [Integer, nil] The sandbox ID
|
|
63
|
+
def inbox_id
|
|
64
|
+
Deprecation.warn('Mailtrap::Client#inbox_id', 'Mailtrap::Client#sandbox_id')
|
|
65
|
+
sandbox_id
|
|
66
|
+
end
|
|
67
|
+
|
|
54
68
|
# Sends a batch of emails.
|
|
55
69
|
# @example Batch sending with template
|
|
56
70
|
# batch_base = Mailtrap::Mail.batch_base_from_template(
|
|
@@ -235,11 +249,11 @@ module Mailtrap
|
|
|
235
249
|
|
|
236
250
|
private
|
|
237
251
|
|
|
238
|
-
def validate_args!(api_key, api_port, bulk, sandbox,
|
|
252
|
+
def validate_args!(api_key, api_port, bulk, sandbox, sandbox_id)
|
|
239
253
|
raise ArgumentError, 'api_key is required' if api_key.nil?
|
|
240
254
|
raise ArgumentError, 'api_port is required' if api_port.nil?
|
|
241
255
|
raise ArgumentError, 'bulk stream is not applicable for sandbox API' if bulk && sandbox
|
|
242
|
-
raise ArgumentError, '
|
|
256
|
+
raise ArgumentError, 'sandbox_id is required for sandbox API' if sandbox && sandbox_id.nil?
|
|
243
257
|
end
|
|
244
258
|
|
|
245
259
|
def select_api_host(bulk:, sandbox:)
|
|
@@ -344,11 +358,11 @@ module Mailtrap
|
|
|
344
358
|
end
|
|
345
359
|
|
|
346
360
|
def send_path
|
|
347
|
-
"/api/send#{"/#{
|
|
361
|
+
"/api/send#{"/#{sandbox_id}" if sandbox}"
|
|
348
362
|
end
|
|
349
363
|
|
|
350
364
|
def batch_request_path
|
|
351
|
-
"/api/batch#{"/#{
|
|
365
|
+
"/api/batch#{"/#{sandbox_id}" if sandbox}"
|
|
352
366
|
end
|
|
353
367
|
end
|
|
354
368
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Mailtrap
|
|
4
|
-
# Data Transfer Object for
|
|
4
|
+
# Data Transfer Object for Domain Company Info
|
|
5
5
|
# @see https://docs.mailtrap.io/developers/management/sending-domains
|
|
6
6
|
# @attr_reader name [String, nil] Company or individual name
|
|
7
7
|
# @attr_reader address [String, nil] Street address
|
|
@@ -22,17 +22,17 @@ module Mailtrap
|
|
|
22
22
|
|
|
23
23
|
self.response_class = CompanyInfo
|
|
24
24
|
|
|
25
|
-
# Gets company information for a
|
|
26
|
-
# @param
|
|
25
|
+
# Gets company information for a domain
|
|
26
|
+
# @param domain_id [Integer] The domain ID
|
|
27
27
|
# @return [CompanyInfo] Company information
|
|
28
28
|
# @!macro api_errors
|
|
29
|
-
def get(
|
|
30
|
-
response = client.get(base_path(
|
|
29
|
+
def get(domain_id)
|
|
30
|
+
response = client.get(base_path(domain_id))
|
|
31
31
|
build_entity(response[:data], CompanyInfo)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
# Creates company information for a
|
|
35
|
-
# @param
|
|
34
|
+
# Creates company information for a domain
|
|
35
|
+
# @param domain_id [Integer] The domain ID
|
|
36
36
|
# @param [Hash] options The company info attributes
|
|
37
37
|
# @option options [String] :name Company or individual name
|
|
38
38
|
# @option options [String] :address Street address
|
|
@@ -47,28 +47,28 @@ module Mailtrap
|
|
|
47
47
|
# @return [CompanyInfo] Created company information
|
|
48
48
|
# @!macro api_errors
|
|
49
49
|
# @raise [ArgumentError] If invalid options are provided
|
|
50
|
-
def create(
|
|
50
|
+
def create(domain_id, options)
|
|
51
51
|
validate_options!(options, supported_options)
|
|
52
|
-
response = client.post(base_path(
|
|
52
|
+
response = client.post(base_path(domain_id), wrap_request(options))
|
|
53
53
|
build_entity(response[:data], CompanyInfo)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
# Updates company information for a
|
|
57
|
-
# @param
|
|
56
|
+
# Updates company information for a domain
|
|
57
|
+
# @param domain_id [Integer] The domain ID
|
|
58
58
|
# @param [Hash] options The company info attributes to update
|
|
59
59
|
# @return [CompanyInfo] Updated company information
|
|
60
60
|
# @!macro api_errors
|
|
61
61
|
# @raise [ArgumentError] If invalid options are provided
|
|
62
|
-
def update(
|
|
62
|
+
def update(domain_id, options)
|
|
63
63
|
validate_options!(options, supported_options)
|
|
64
|
-
response = client.patch(base_path(
|
|
64
|
+
response = client.patch(base_path(domain_id), wrap_request(options))
|
|
65
65
|
build_entity(response[:data], CompanyInfo)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
private
|
|
69
69
|
|
|
70
|
-
def base_path(
|
|
71
|
-
"/api/accounts/#{account_id}/sending_domains/#{
|
|
70
|
+
def base_path(domain_id)
|
|
71
|
+
"/api/accounts/#{account_id}/sending_domains/#{domain_id}/company_info"
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def wrap_request(options)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'set'
|
|
4
|
+
|
|
5
|
+
module Mailtrap
|
|
6
|
+
# Emits a deprecation warning once per process for each deprecated name, and maps the
|
|
7
|
+
# deprecated inbox_id onto sandbox_id.
|
|
8
|
+
# @api private
|
|
9
|
+
module Deprecation
|
|
10
|
+
WARNED = Set.new
|
|
11
|
+
MUTEX = Mutex.new
|
|
12
|
+
|
|
13
|
+
# Call it directly from the deprecated method: the warning points at that method's caller.
|
|
14
|
+
# @param old_name [String] The deprecated name
|
|
15
|
+
# @param new_name [String] The name to use instead
|
|
16
|
+
def self.warn(old_name, new_name)
|
|
17
|
+
return unless MUTEX.synchronize { WARNED.add?(old_name) }
|
|
18
|
+
|
|
19
|
+
Kernel.warn(
|
|
20
|
+
"[mailtrap] #{old_name} is deprecated and will be removed in a future major release; " \
|
|
21
|
+
"use #{new_name} instead.",
|
|
22
|
+
uplevel: 2
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @param sandbox_id [Integer, String, nil] The ID given as sandbox_id
|
|
27
|
+
# @param inbox_id [Integer, String] The ID given as the deprecated inbox_id
|
|
28
|
+
# @return [Integer, String] The sandbox ID to use
|
|
29
|
+
# @raise [ArgumentError] If both IDs are given and differ
|
|
30
|
+
def self.resolve_sandbox_id(sandbox_id, inbox_id)
|
|
31
|
+
return inbox_id if sandbox_id.nil?
|
|
32
|
+
return sandbox_id if sandbox_id.to_s == inbox_id.to_s
|
|
33
|
+
|
|
34
|
+
raise ArgumentError, 'sandbox_id and inbox_id differ; pass only sandbox_id'
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Domain
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/management/sending-domains
|
|
6
|
+
# @attr_reader id [Integer] The domain ID
|
|
7
|
+
# @attr_reader domain_name [String] The domain name
|
|
8
|
+
# @attr_reader demo [Boolean] Whether the domain is a demo domain
|
|
9
|
+
# @attr_reader compliance_status [String] The compliance status of the domain
|
|
10
|
+
# @attr_reader dns_verified [Boolean] Whether the DNS records are verified
|
|
11
|
+
# @attr_reader dns_verified_at [String, nil] The timestamp when DNS was verified
|
|
12
|
+
# @attr_reader dns_records [Array] The DNS records for the domain
|
|
13
|
+
# @attr_reader open_tracking_enabled [Boolean] Whether open tracking is enabled
|
|
14
|
+
# @attr_reader click_tracking_enabled [Boolean] Whether click tracking is enabled
|
|
15
|
+
# @attr_reader tracking_opt_out_enabled [Boolean] Whether the tracking opt-out link is enabled
|
|
16
|
+
# @attr_reader auto_unsubscribe_link_enabled [Boolean] Whether auto unsubscribe link is enabled
|
|
17
|
+
# @attr_reader custom_domain_tracking_enabled [Boolean] Whether custom domain tracking is enabled
|
|
18
|
+
# @attr_reader health_alerts_enabled [Boolean] Whether health alerts are enabled
|
|
19
|
+
# @attr_reader critical_alerts_enabled [Boolean] Whether critical alerts are enabled
|
|
20
|
+
# @attr_reader alert_recipient_email [String, nil] The email address for alert recipients
|
|
21
|
+
# @attr_reader inbound_enabled [Boolean] Whether inbound email is enabled for this domain
|
|
22
|
+
# @attr_reader inbound_verified [Boolean] Whether the domain's inbound MX records are verified
|
|
23
|
+
# @attr_reader permissions [Hash] The permissions for the domain
|
|
24
|
+
#
|
|
25
|
+
Domain = Struct.new(
|
|
26
|
+
:id,
|
|
27
|
+
:domain_name,
|
|
28
|
+
:demo,
|
|
29
|
+
:compliance_status,
|
|
30
|
+
:dns_verified,
|
|
31
|
+
:dns_verified_at,
|
|
32
|
+
:dns_records,
|
|
33
|
+
:open_tracking_enabled,
|
|
34
|
+
:click_tracking_enabled,
|
|
35
|
+
:tracking_opt_out_enabled,
|
|
36
|
+
:auto_unsubscribe_link_enabled,
|
|
37
|
+
:custom_domain_tracking_enabled,
|
|
38
|
+
:health_alerts_enabled,
|
|
39
|
+
:critical_alerts_enabled,
|
|
40
|
+
:alert_recipient_email,
|
|
41
|
+
:inbound_enabled,
|
|
42
|
+
:inbound_verified,
|
|
43
|
+
:permissions,
|
|
44
|
+
:created_at,
|
|
45
|
+
:updated_at,
|
|
46
|
+
keyword_init: true
|
|
47
|
+
)
|
|
48
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'domain'
|
|
5
|
+
|
|
6
|
+
module Mailtrap
|
|
7
|
+
class DomainsAPI
|
|
8
|
+
include BaseAPI
|
|
9
|
+
|
|
10
|
+
self.supported_options = %i[
|
|
11
|
+
open_tracking_enabled
|
|
12
|
+
click_tracking_enabled
|
|
13
|
+
tracking_opt_out_enabled
|
|
14
|
+
auto_unsubscribe_link_enabled
|
|
15
|
+
inbound_enabled
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
self.response_class = Domain
|
|
19
|
+
|
|
20
|
+
# Lists all domains for the account
|
|
21
|
+
# @return [Array<Domain>] Array of domains
|
|
22
|
+
# @!macro api_errors
|
|
23
|
+
def list
|
|
24
|
+
response = client.get(base_path)
|
|
25
|
+
response[:data].map { |item| handle_response(item) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Retrieves a specific domain
|
|
29
|
+
# @param domain_id [Integer] The domain ID
|
|
30
|
+
# @return [Domain] Domain object
|
|
31
|
+
# @!macro api_errors
|
|
32
|
+
def get(domain_id)
|
|
33
|
+
base_get(domain_id)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Creates a new domain
|
|
37
|
+
# @param [Hash] options The parameters to create
|
|
38
|
+
# @option options [String] :domain_name The domain name
|
|
39
|
+
# @return [Domain] Created domain
|
|
40
|
+
# @!macro api_errors
|
|
41
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
42
|
+
def create(options)
|
|
43
|
+
base_create(options, %i[domain_name])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Deletes a domain
|
|
47
|
+
# @param domain_id [Integer] The domain ID
|
|
48
|
+
# @return nil
|
|
49
|
+
# @!macro api_errors
|
|
50
|
+
def delete(domain_id)
|
|
51
|
+
base_delete(domain_id)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Updates configuration settings for a domain
|
|
55
|
+
# @param domain_id [Integer] The domain ID
|
|
56
|
+
# @param [Hash] options The parameters to update
|
|
57
|
+
# @option options [Boolean] :open_tracking_enabled Enable open tracking for emails sent from this domain
|
|
58
|
+
# @option options [Boolean] :click_tracking_enabled Enable click tracking for links in emails sent from this domain
|
|
59
|
+
# @option options [Boolean] :tracking_opt_out_enabled Enable the tracking opt-out link in tracked emails
|
|
60
|
+
# @option options [Boolean] :auto_unsubscribe_link_enabled Automatically add an unsubscribe link to emails
|
|
61
|
+
# @option options [Boolean] :inbound_enabled Enable inbound email for this domain
|
|
62
|
+
# @return [Domain] Updated domain
|
|
63
|
+
# @!macro api_errors
|
|
64
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
65
|
+
def update(domain_id, options)
|
|
66
|
+
base_update(domain_id, options)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Email DNS configuration instructions for the domain
|
|
70
|
+
# @param domain_id [Integer] The domain ID
|
|
71
|
+
# @param email [String] The email for instructions
|
|
72
|
+
# @return nil
|
|
73
|
+
# @!macro api_errors
|
|
74
|
+
def send_setup_instructions(domain_id, email:)
|
|
75
|
+
client.post("#{base_path}/#{domain_id}/send_setup_instructions", email:)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def base_path
|
|
81
|
+
"/api/accounts/#{account_id}/sending_domains"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def wrap_request(options)
|
|
85
|
+
{ sending_domain: options }
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -39,9 +39,9 @@ module Mailtrap
|
|
|
39
39
|
# Data Transfer Object for Email Campaign
|
|
40
40
|
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/email-campaigns
|
|
41
41
|
# @attr_reader id [Integer] The email campaign ID
|
|
42
|
-
# @attr_reader domain_id [Integer] ID of the
|
|
43
|
-
# as returned by the
|
|
44
|
-
# @attr_reader domain_name [String] Name of the
|
|
42
|
+
# @attr_reader domain_id [Integer] ID of the domain used for the campaign,
|
|
43
|
+
# as returned by the Domains endpoints
|
|
44
|
+
# @attr_reader domain_name [String] Name of the domain used for the campaign
|
|
45
45
|
# @attr_reader name [String] Campaign name
|
|
46
46
|
# @attr_reader from_local_part [String] Local part (before the @) of the From address
|
|
47
47
|
# @attr_reader from_display_name [String] Display name shown in the From header
|
|
@@ -58,8 +58,8 @@ module Mailtrap
|
|
|
58
58
|
# Creates a new email campaign in the +draft+ state
|
|
59
59
|
# @param [Hash] options The parameters to create
|
|
60
60
|
# @option options [String] :name Campaign name (required)
|
|
61
|
-
# @option options [Integer] :domain_id ID of the verified
|
|
62
|
-
# as returned by the
|
|
61
|
+
# @option options [Integer] :domain_id ID of the verified domain (required),
|
|
62
|
+
# as returned by the Domains endpoints
|
|
63
63
|
# @option options [String] :from_display_name Display name shown in the From header
|
|
64
64
|
# @option options [String] :from_local_part Local part (before the @) of the From address (required)
|
|
65
65
|
# @option options [Hash] :reply_to Reply-To address parts (+display_name+, +local_part+, +domain+)
|
|
@@ -82,8 +82,8 @@ module Mailtrap
|
|
|
82
82
|
# @param email_campaign_id [Integer] The email campaign ID
|
|
83
83
|
# @param [Hash] options The parameters to update; accepts the same fields as {#create}
|
|
84
84
|
# @option options [String] :name Campaign name
|
|
85
|
-
# @option options [Integer] :domain_id ID of the verified
|
|
86
|
-
# as returned by the
|
|
85
|
+
# @option options [Integer] :domain_id ID of the verified domain,
|
|
86
|
+
# as returned by the Domains endpoints
|
|
87
87
|
# @option options [String] :from_display_name Display name shown in the From header
|
|
88
88
|
# @option options [String] :from_local_part Local part (before the @) of the From address
|
|
89
89
|
# @option options [Hash] :reply_to Reply-To address parts (+display_name+, +local_part+, +domain+)
|
|
@@ -17,7 +17,7 @@ module Mailtrap
|
|
|
17
17
|
# @attr_reader category [String, nil] Message category
|
|
18
18
|
# @attr_reader custom_variables [Hash, nil] Custom variables
|
|
19
19
|
# @attr_reader sending_stream [String] transactional or bulk
|
|
20
|
-
# @attr_reader sending_domain_id [Integer]
|
|
20
|
+
# @attr_reader sending_domain_id [Integer] Domain ID
|
|
21
21
|
# @attr_reader template_id [Integer, nil] Template ID if sent from template
|
|
22
22
|
# @attr_reader template_variables [Hash, nil] Template variables
|
|
23
23
|
# @attr_reader opens_count [Integer] Number of opens
|
|
@@ -6,7 +6,7 @@ module Mailtrap
|
|
|
6
6
|
# @attr_reader id [Integer] The inbox ID
|
|
7
7
|
# @attr_reader name [String] The inbox name
|
|
8
8
|
# @attr_reader address [String] The inbox's inbound address
|
|
9
|
-
# @attr_reader domain_id [Integer] The
|
|
9
|
+
# @attr_reader domain_id [Integer] The domain the inbox is attached to
|
|
10
10
|
InboundInbox = Struct.new(
|
|
11
11
|
:id,
|
|
12
12
|
:name,
|
data/lib/mailtrap/inbox.rb
CHANGED
|
@@ -1,57 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'sandbox'
|
|
4
|
+
|
|
3
5
|
module Mailtrap
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
# @attr_reader name [String] The inbox name
|
|
8
|
-
# @attr_reader username [String] The inbox username
|
|
9
|
-
# @attr_reader password [String, nil] The inbox password
|
|
10
|
-
# @attr_reader max_size [Integer] The maximum inbox size in MB
|
|
11
|
-
# @attr_reader status [String] The inbox status
|
|
12
|
-
# @attr_reader email_username [String] The email username
|
|
13
|
-
# @attr_reader email_username_enabled [Boolean] Whether the email username is enabled
|
|
14
|
-
# @attr_reader sent_messages_count [Integer] The count of sent messages
|
|
15
|
-
# @attr_reader forwarded_messages_count [Integer] The count of forwarded messages
|
|
16
|
-
# @attr_reader used [Integer] The used inbox size in MB
|
|
17
|
-
# @attr_reader forward_from_email_address [String] The forwarding email address
|
|
18
|
-
# @attr_reader project_id [Integer] The associated project ID
|
|
19
|
-
# @attr_reader domain [String] The inbox domain
|
|
20
|
-
# @attr_reader pop3_domain [String] The POP3 domain
|
|
21
|
-
# @attr_reader email_domain [String] The email domain
|
|
22
|
-
# @attr_reader api_domain [String] The API domain
|
|
23
|
-
# @attr_reader emails_count [Integer] The total number of emails
|
|
24
|
-
# @attr_reader emails_unread_count [Integer] The number of unread emails
|
|
25
|
-
# @attr_reader last_message_sent_at [String, nil] The timestamp of the last sent message
|
|
26
|
-
# @attr_reader smtp_ports [Array<Integer>] The list of SMTP ports
|
|
27
|
-
# @attr_reader pop3_ports [Array<Integer>] The list of POP3 ports
|
|
28
|
-
# @attr_reader max_message_size [Integer] The maximum message size in MB
|
|
29
|
-
# @attr_reader permissions [Hash] List of permissions
|
|
30
|
-
Inbox = Struct.new(
|
|
31
|
-
:id,
|
|
32
|
-
:name,
|
|
33
|
-
:username,
|
|
34
|
-
:password,
|
|
35
|
-
:max_size,
|
|
36
|
-
:status,
|
|
37
|
-
:email_username,
|
|
38
|
-
:email_username_enabled,
|
|
39
|
-
:sent_messages_count,
|
|
40
|
-
:forwarded_messages_count,
|
|
41
|
-
:used,
|
|
42
|
-
:forward_from_email_address,
|
|
43
|
-
:project_id,
|
|
44
|
-
:domain,
|
|
45
|
-
:pop3_domain,
|
|
46
|
-
:email_domain,
|
|
47
|
-
:api_domain,
|
|
48
|
-
:emails_count,
|
|
49
|
-
:emails_unread_count,
|
|
50
|
-
:last_message_sent_at,
|
|
51
|
-
:smtp_ports,
|
|
52
|
-
:pop3_ports,
|
|
53
|
-
:max_message_size,
|
|
54
|
-
:permissions,
|
|
55
|
-
keyword_init: true
|
|
56
|
-
)
|
|
6
|
+
# @deprecated Use {Sandbox} instead.
|
|
7
|
+
Inbox = Sandbox
|
|
8
|
+
deprecate_constant :Inbox
|
|
57
9
|
end
|