mailtrap 2.3.0 → 2.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/.rubocop.yml +12 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +46 -19
- data/README.md +92 -6
- data/lib/mailtrap/base_api.rb +84 -0
- data/lib/mailtrap/client.rb +198 -27
- data/lib/mailtrap/contact.rb +38 -0
- data/lib/mailtrap/contact_field.rb +18 -0
- data/lib/mailtrap/contact_fields_api.rb +67 -0
- data/lib/mailtrap/contact_list.rb +14 -0
- data/lib/mailtrap/contact_lists_api.rb +64 -0
- data/lib/mailtrap/contacts_api.rb +90 -0
- data/lib/mailtrap/email_template.rb +35 -0
- data/lib/mailtrap/email_templates_api.rb +76 -0
- data/lib/mailtrap/mail/base.rb +17 -6
- data/lib/mailtrap/mail/from_template.rb +3 -24
- data/lib/mailtrap/mail.rb +180 -26
- data/lib/mailtrap/version.rb +1 -1
- data/lib/mailtrap.rb +11 -1
- data/mailtrap.gemspec +2 -0
- metadata +26 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5d46743b2ae7145ba69ca1b276417baa829601436e84653ce38ba0154a3dde5
|
4
|
+
data.tar.gz: 9eaf365adb12ab38f7ae908ec3c70e62885e8eda080e302bc5453100b8dca557
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17b164ff3752f9b768554bc4959e66323bc523f8cff2de24ee06c3c7274b92f28607f4de1aaf8894e92238b7cba40ebc7cb667405ff1bd4770bc707bac6d79ca
|
7
|
+
data.tar.gz: a7854620322960ccb356aa1dd84943a7e562b65ebd042d4288cfc8b3364004694776301f49a12383ebbd80a0c98c7bdfa8b9de7e4d36295ce03f500edc199336
|
data/.rubocop.yml
CHANGED
@@ -15,6 +15,15 @@ AllCops:
|
|
15
15
|
Layout/LineLength:
|
16
16
|
Max: 120
|
17
17
|
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Max: 25
|
20
|
+
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Max: 200
|
23
|
+
|
24
|
+
Metrics/MethodLength:
|
25
|
+
Max: 20
|
26
|
+
|
18
27
|
Naming/MethodParameterName:
|
19
28
|
MinNameLength: 2
|
20
29
|
|
@@ -27,6 +36,9 @@ RSpec/MultipleExpectations:
|
|
27
36
|
RSpec/NestedGroups:
|
28
37
|
Max: 4
|
29
38
|
|
39
|
+
RSpec/ExampleLength:
|
40
|
+
Enabled: false
|
41
|
+
|
30
42
|
Style/Documentation:
|
31
43
|
Enabled: false
|
32
44
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [2.4.0] - 2025-08-04
|
2
|
+
|
3
|
+
- Add Email Templates API
|
4
|
+
- Add Contacts API
|
5
|
+
- Add Contact Fields API
|
6
|
+
- Add Contact Lists API
|
7
|
+
- Add Batch Sending
|
8
|
+
- Deprecate `Mailtrap::Mail::FromTemplate` in favour of `Mailtrap::Mail.from_template`
|
9
|
+
|
1
10
|
## [2.3.0] - 2025-03-06
|
2
11
|
|
3
12
|
- Drop Ruby 3.0 support
|
data/Gemfile
CHANGED
@@ -5,9 +5,11 @@ source 'https://rubygems.org'
|
|
5
5
|
gemspec
|
6
6
|
|
7
7
|
gem 'appraisal'
|
8
|
+
gem 'irb'
|
8
9
|
gem 'mail'
|
9
10
|
gem 'net-smtp'
|
10
11
|
gem 'rake', '~> 13.0'
|
12
|
+
gem 'rdoc', '~> 6.13.0'
|
11
13
|
gem 'rspec', '~> 3.0'
|
12
14
|
gem 'rspec-its'
|
13
15
|
gem 'rubocop', '~> 1.21'
|
@@ -15,3 +17,4 @@ gem 'rubocop-rake', require: false
|
|
15
17
|
gem 'rubocop-rspec', require: false
|
16
18
|
gem 'vcr'
|
17
19
|
gem 'webmock'
|
20
|
+
gem 'yard', '~> 0.9'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mailtrap (2.
|
4
|
+
mailtrap (2.4.0)
|
5
|
+
base64
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -12,7 +13,8 @@ GEM
|
|
12
13
|
bundler
|
13
14
|
rake
|
14
15
|
thor (>= 0.14.0)
|
15
|
-
ast (2.4.
|
16
|
+
ast (2.4.3)
|
17
|
+
base64 (0.3.0)
|
16
18
|
bigdecimal (3.1.8)
|
17
19
|
crack (1.0.0)
|
18
20
|
bigdecimal
|
@@ -20,15 +22,21 @@ GEM
|
|
20
22
|
date (3.4.1)
|
21
23
|
diff-lcs (1.5.1)
|
22
24
|
hashdiff (1.1.0)
|
23
|
-
|
24
|
-
|
25
|
+
io-console (0.8.0)
|
26
|
+
irb (1.15.2)
|
27
|
+
pp (>= 0.6.0)
|
28
|
+
rdoc (>= 4.0.0)
|
29
|
+
reline (>= 0.4.2)
|
30
|
+
json (2.12.2)
|
31
|
+
language_server-protocol (3.17.0.5)
|
32
|
+
lint_roller (1.1.0)
|
25
33
|
mail (2.8.1)
|
26
34
|
mini_mime (>= 0.1.1)
|
27
35
|
net-imap
|
28
36
|
net-pop
|
29
37
|
net-smtp
|
30
38
|
mini_mime (1.1.5)
|
31
|
-
net-imap (0.5.
|
39
|
+
net-imap (0.5.7)
|
32
40
|
date
|
33
41
|
net-protocol
|
34
42
|
net-pop (0.1.2)
|
@@ -37,16 +45,27 @@ GEM
|
|
37
45
|
timeout
|
38
46
|
net-smtp (0.5.0)
|
39
47
|
net-protocol
|
40
|
-
parallel (1.
|
41
|
-
parser (3.3.
|
48
|
+
parallel (1.27.0)
|
49
|
+
parser (3.3.8.0)
|
42
50
|
ast (~> 2.4.1)
|
43
51
|
racc
|
52
|
+
pp (0.6.2)
|
53
|
+
prettyprint
|
54
|
+
prettyprint (0.2.0)
|
55
|
+
prism (1.4.0)
|
56
|
+
psych (5.2.6)
|
57
|
+
date
|
58
|
+
stringio
|
44
59
|
public_suffix (5.1.1)
|
45
|
-
racc (1.8.
|
60
|
+
racc (1.8.1)
|
46
61
|
rainbow (3.1.1)
|
47
62
|
rake (13.2.1)
|
48
|
-
|
49
|
-
|
63
|
+
rdoc (6.13.1)
|
64
|
+
psych (>= 4.0.0)
|
65
|
+
regexp_parser (2.10.0)
|
66
|
+
reline (0.6.1)
|
67
|
+
io-console (~> 0.5)
|
68
|
+
rexml (3.4.1)
|
50
69
|
rspec (3.13.0)
|
51
70
|
rspec-core (~> 3.13.0)
|
52
71
|
rspec-expectations (~> 3.13.0)
|
@@ -63,42 +82,49 @@ GEM
|
|
63
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
83
|
rspec-support (~> 3.13.0)
|
65
84
|
rspec-support (3.13.1)
|
66
|
-
rubocop (1.
|
85
|
+
rubocop (1.78.0)
|
67
86
|
json (~> 2.3)
|
68
|
-
language_server-protocol (
|
87
|
+
language_server-protocol (~> 3.17.0.2)
|
88
|
+
lint_roller (~> 1.1.0)
|
69
89
|
parallel (~> 1.10)
|
70
90
|
parser (>= 3.3.0.2)
|
71
91
|
rainbow (>= 2.2.2, < 4.0)
|
72
|
-
regexp_parser (>=
|
73
|
-
|
74
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
92
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
93
|
+
rubocop-ast (>= 1.45.1, < 2.0)
|
75
94
|
ruby-progressbar (~> 1.7)
|
76
|
-
unicode-display_width (>= 2.4.0, <
|
77
|
-
rubocop-ast (1.
|
78
|
-
parser (>= 3.3.
|
95
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
96
|
+
rubocop-ast (1.45.1)
|
97
|
+
parser (>= 3.3.7.2)
|
98
|
+
prism (~> 1.4)
|
79
99
|
rubocop-rake (0.6.0)
|
80
100
|
rubocop (~> 1.0)
|
81
101
|
rubocop-rspec (3.0.2)
|
82
102
|
rubocop (~> 1.61)
|
83
103
|
ruby-progressbar (1.13.0)
|
104
|
+
stringio (3.1.7)
|
84
105
|
thor (1.3.1)
|
85
106
|
timeout (0.4.3)
|
86
|
-
unicode-display_width (
|
107
|
+
unicode-display_width (3.1.4)
|
108
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
109
|
+
unicode-emoji (4.0.4)
|
87
110
|
vcr (6.2.0)
|
88
111
|
webmock (3.23.1)
|
89
112
|
addressable (>= 2.8.0)
|
90
113
|
crack (>= 0.3.2)
|
91
114
|
hashdiff (>= 0.4.0, < 2.0.0)
|
115
|
+
yard (0.9.37)
|
92
116
|
|
93
117
|
PLATFORMS
|
94
118
|
ruby
|
95
119
|
|
96
120
|
DEPENDENCIES
|
97
121
|
appraisal
|
122
|
+
irb
|
98
123
|
mail
|
99
124
|
mailtrap!
|
100
125
|
net-smtp
|
101
126
|
rake (~> 13.0)
|
127
|
+
rdoc (~> 6.13.0)
|
102
128
|
rspec (~> 3.0)
|
103
129
|
rspec-its
|
104
130
|
rubocop (~> 1.21)
|
@@ -106,6 +132,7 @@ DEPENDENCIES
|
|
106
132
|
rubocop-rspec
|
107
133
|
vcr
|
108
134
|
webmock
|
135
|
+
yard (~> 0.9)
|
109
136
|
|
110
137
|
BUNDLED WITH
|
111
138
|
2.6.5
|
data/README.md
CHANGED
@@ -46,27 +46,89 @@ config.action_mailer.delivery_method = :mailtrap
|
|
46
46
|
```ruby
|
47
47
|
require 'mailtrap'
|
48
48
|
|
49
|
-
#
|
50
|
-
mail = Mailtrap::Mail
|
49
|
+
# Create mail object
|
50
|
+
mail = Mailtrap::Mail.from_content(
|
51
51
|
from: { email: 'mailtrap@example.com', name: 'Mailtrap Test' },
|
52
52
|
to: [
|
53
53
|
{ email: 'your@email.com' }
|
54
54
|
],
|
55
55
|
reply_to: { email: 'support@example.com', name: 'Mailtrap Reply-To' },
|
56
56
|
subject: 'You are awesome!',
|
57
|
-
text:
|
57
|
+
text: 'Congrats for sending test email with Mailtrap!'
|
58
58
|
)
|
59
59
|
|
60
|
-
#
|
60
|
+
# Create client and send
|
61
61
|
client = Mailtrap::Client.new(api_key: 'your-api-key')
|
62
62
|
client.send(mail)
|
63
|
+
|
64
|
+
# You can also pass the request parameters directly
|
65
|
+
client.send(
|
66
|
+
from: { email: 'mailtrap@example.com', name: 'Mailtrap Test' },
|
67
|
+
to: [
|
68
|
+
{ email: 'your@email.com' }
|
69
|
+
],
|
70
|
+
subject: 'You are awesome!',
|
71
|
+
text: 'Congrats for sending test email with Mailtrap!'
|
72
|
+
)
|
73
|
+
|
74
|
+
```
|
75
|
+
|
76
|
+
### Batch Sending
|
77
|
+
|
78
|
+
Send up to 500 emails in one API call:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
require 'mailtrap'
|
82
|
+
|
83
|
+
client = Mailtrap::Client.new(api_key: 'your-api-key')
|
84
|
+
|
85
|
+
batch_base = Mailtrap::Mail.batch_base_from_content(
|
86
|
+
from: { email: 'mailtrap@demomailtrap.co', name: 'Mailtrap Test' },
|
87
|
+
subject: 'You are awesome!',
|
88
|
+
text: 'Congrats for sending test email with Mailtrap!',
|
89
|
+
html: '<p>Congrats for sending test email with Mailtrap!</p>'
|
90
|
+
)
|
91
|
+
|
92
|
+
client.send_batch(
|
93
|
+
batch_base, [
|
94
|
+
Mailtrap::Mail.from_content(
|
95
|
+
to: [
|
96
|
+
{ email: 'john.doe@email.com', name: 'John Doe' }
|
97
|
+
]
|
98
|
+
),
|
99
|
+
Mailtrap::Mail.from_content(
|
100
|
+
to: [
|
101
|
+
{ email: 'jane.doe@email.com', name: 'Jane Doe' }
|
102
|
+
]
|
103
|
+
)
|
104
|
+
]
|
105
|
+
)
|
106
|
+
```
|
107
|
+
|
108
|
+
### Email Templates API
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
require 'mailtrap'
|
112
|
+
|
113
|
+
client = Mailtrap::Client.new(api_key: 'your-api-key')
|
114
|
+
templates = Mailtrap::EmailTemplatesAPI.new 3229, client
|
115
|
+
|
116
|
+
templates.create(
|
117
|
+
name: 'Welcome Email',
|
118
|
+
subject: 'Welcome to Mailtrap!',
|
119
|
+
body_html: '<h1>Hello</h1>',
|
120
|
+
body_text: 'Hello',
|
121
|
+
category: 'welcome'
|
122
|
+
)
|
63
123
|
```
|
64
124
|
|
65
|
-
Refer to the [`examples`](examples) folder for more examples
|
125
|
+
Refer to the [`examples`](examples) folder for more examples:
|
66
126
|
|
67
127
|
- [Full](examples/full.rb)
|
68
128
|
- [Email template](examples/email_template.rb)
|
129
|
+
- [Batch Sending](examples/batch.rb)
|
69
130
|
- [ActionMailer](examples/action_mailer.rb)
|
131
|
+
- [Email Templates API](examples/email_templates_api.rb)
|
70
132
|
|
71
133
|
### Content-Transfer-Encoding
|
72
134
|
|
@@ -77,11 +139,35 @@ sending. For example, `/api/send` endpoint ignores `Content-Transfer-Encoding`
|
|
77
139
|
Meaning your recipients will receive emails only in the default encoding which
|
78
140
|
is `quoted-printable`, if you send with Mailtrap API.
|
79
141
|
|
80
|
-
For those who
|
142
|
+
For those who need to use `7bit` or any other encoding, SMTP provides
|
81
143
|
better flexibility in that regard. Go to your _Mailtrap account_ → _Email Sending_
|
82
144
|
→ _Sending Domains_ → _Your domain_ → _SMTP/API Settings_ to find the SMTP
|
83
145
|
configuration example.
|
84
146
|
|
147
|
+
### Multiple Mailtrap Clients
|
148
|
+
|
149
|
+
You can configure two Mailtrap clients to operate simultaneously. This setup is
|
150
|
+
particularly useful when you need to send emails using both the transactional
|
151
|
+
and bulk APIs. Refer to the configuration example below:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
# config/application.rb
|
155
|
+
ActionMailer::Base.add_delivery_method :mailtrap_bulk, Mailtrap::ActionMailer::DeliveryMethod
|
156
|
+
|
157
|
+
# config/environments/production.rb
|
158
|
+
config.action_mailer.delivery_method = :mailtrap
|
159
|
+
config.action_mailer.mailtrap_settings = {
|
160
|
+
api_key: 'your-api-key'
|
161
|
+
}
|
162
|
+
config.action_mailer.mailtrap_bulk_settings = {
|
163
|
+
api_key: 'your-api-key',
|
164
|
+
bulk: true
|
165
|
+
}
|
166
|
+
|
167
|
+
# app/mailers/foo_mailer.rb
|
168
|
+
mail(delivery_method: :mailtrap_bulk)
|
169
|
+
```
|
170
|
+
|
85
171
|
## Migration guide v1 → v2
|
86
172
|
|
87
173
|
Change `Mailtrap::Sending::Client` to `Mailtrap::Client`.
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mailtrap
|
4
|
+
module BaseAPI
|
5
|
+
attr_reader :account_id, :client
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
attr_accessor :supported_options, :response_class
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param account_id [Integer] The account ID
|
16
|
+
# @param client [Mailtrap::Client] The client instance
|
17
|
+
# @raise [ArgumentError] If account_id is nil
|
18
|
+
def initialize(account_id = ENV.fetch('MAILTRAP_ACCOUNT_ID'), client = Mailtrap::Client.new)
|
19
|
+
raise ArgumentError, 'account_id is required' if account_id.nil?
|
20
|
+
|
21
|
+
@account_id = account_id
|
22
|
+
@client = client
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def supported_options
|
28
|
+
self.class.supported_options
|
29
|
+
end
|
30
|
+
|
31
|
+
def response_class
|
32
|
+
self.class.response_class
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_options!(options, supported_options)
|
36
|
+
invalid_options = options.keys - supported_options
|
37
|
+
return if invalid_options.empty?
|
38
|
+
|
39
|
+
raise ArgumentError, "invalid options are given: #{invalid_options}, supported_options: #{supported_options}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_entity(options, response_class)
|
43
|
+
response_class.new(options.slice(*response_class.members))
|
44
|
+
end
|
45
|
+
|
46
|
+
def base_get(id)
|
47
|
+
response = client.get("#{base_path}/#{id}")
|
48
|
+
handle_response(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
def base_create(options, supported_options_override = supported_options)
|
52
|
+
validate_options!(options, supported_options_override)
|
53
|
+
response = client.post(base_path, wrap_request(options))
|
54
|
+
handle_response(response)
|
55
|
+
end
|
56
|
+
|
57
|
+
def base_update(id, options, supported_options_override = supported_options)
|
58
|
+
validate_options!(options, supported_options_override)
|
59
|
+
response = client.patch("#{base_path}/#{id}", wrap_request(options))
|
60
|
+
handle_response(response)
|
61
|
+
end
|
62
|
+
|
63
|
+
def base_delete(id)
|
64
|
+
client.delete("#{base_path}/#{id}")
|
65
|
+
end
|
66
|
+
|
67
|
+
def base_list
|
68
|
+
response = client.get(base_path)
|
69
|
+
response.map { |item| handle_response(item) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def handle_response(response)
|
73
|
+
build_entity(response, response_class)
|
74
|
+
end
|
75
|
+
|
76
|
+
def wrap_request(options)
|
77
|
+
options
|
78
|
+
end
|
79
|
+
|
80
|
+
def base_path
|
81
|
+
raise NotImplementedError, 'base_path must be implemented in the including class'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|