mailslurp_client 15.18.3 → 15.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +66 -9
- data/lib/mailslurp_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed313a19e0624c0e3a672c95efd493057e607db56e8d5431160f7ac8de3526f8
|
4
|
+
data.tar.gz: 5f37dedf55ec71aaf7a7b25123fd4b31d6254a2349a19a363e26c708e4a608ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1de0d33b238d1c01d094ca5ae4f14cbad29b66197cafb404412e1d050e210cfa33ce091dab1adacb1047e6bdda970ae8a6d842471232c775196ecc37f4f1bf21
|
7
|
+
data.tar.gz: 23b68015f53717f1983db6ee6a3b3eef6b0a42d71190b1d2b45c328a382dcd373b44f39db59a066094b794999a5927a7b8b04a140569516136aa5e5224bf5c0d
|
data/README.md
CHANGED
@@ -50,7 +50,12 @@ gem install mailslurp_client
|
|
50
50
|
|
51
51
|
Or in your `Gemfile`:
|
52
52
|
|
53
|
-
|
53
|
+
```ruby
|
54
|
+
source "https://rubygems.org"
|
55
|
+
|
56
|
+
gem 'mailslurp_client'
|
57
|
+
gem 'typhoeus'
|
58
|
+
```
|
54
59
|
|
55
60
|
And then run bundler install:
|
56
61
|
|
@@ -67,15 +72,22 @@ You may need to install `typhoeus` if you encounter libcurl errors.
|
|
67
72
|
gem 'typhoeus'
|
68
73
|
```
|
69
74
|
|
70
|
-
|
71
75
|
### Configure the client
|
72
76
|
|
73
|
-
|
77
|
+
```ruby
|
78
|
+
require 'mailslurp_client'
|
79
|
+
|
80
|
+
MailSlurpClient.configure do |config|
|
81
|
+
config.api_key['x-api-key'] = ENV['API_KEY']
|
82
|
+
end
|
83
|
+
```
|
74
84
|
|
75
85
|
### Create controllers
|
76
86
|
To call the API create a controller like this:
|
77
87
|
|
78
|
-
|
88
|
+
```ruby
|
89
|
+
inbox_controller = MailSlurpClient::InboxControllerApi.new
|
90
|
+
```
|
79
91
|
|
80
92
|
## Common uses
|
81
93
|
|
@@ -87,7 +99,14 @@ Here are some common uses:
|
|
87
99
|
|
88
100
|
To use MailSlurp you need to create inboxes. These are email accounts that have an ID and a real email address. See methods on the [inbox controller](https://ruby.mailslurp.com/MailSlurpClient/InboxControllerApi.html) for more information.
|
89
101
|
|
90
|
-
|
102
|
+
```ruby
|
103
|
+
options = {
|
104
|
+
name: "My test inbox",
|
105
|
+
inboxType: "SMTP_INBOX"
|
106
|
+
}
|
107
|
+
inbox = inbox_controller.create_inbox_with_options(options)
|
108
|
+
assert_match /@mailslurp/, inbox.email_address
|
109
|
+
```
|
91
110
|
|
92
111
|
In a test:
|
93
112
|
|
@@ -199,7 +218,13 @@ end
|
|
199
218
|
|
200
219
|
You can send HTML emails easily with the inbox controller. First create an inbox then use its ID with the `send_email` method.
|
201
220
|
|
202
|
-
|
221
|
+
```ruby
|
222
|
+
inbox_controller.send_email(inbox.id, {
|
223
|
+
to: [inbox.email_address],
|
224
|
+
subject: "Hello",
|
225
|
+
body: "Welcome. Your code is: 123456",
|
226
|
+
})
|
227
|
+
```
|
203
228
|
|
204
229
|
To send attachments see the [Method Documentation](https://ruby.mailslurp.com/).
|
205
230
|
|
@@ -242,7 +267,27 @@ inbox_controller.send_email(inbox_1.id, opts)
|
|
242
267
|
|
243
268
|
### Send with SMTP
|
244
269
|
|
245
|
-
|
270
|
+
```ruby
|
271
|
+
require 'net/smtp'
|
272
|
+
access_details = inbox_controller.get_imap_smtp_access(inbox_id: inbox.id)
|
273
|
+
Net::SMTP.start(
|
274
|
+
address= access_details.secure_smtp_server_host,
|
275
|
+
port= access_details.secure_smtp_server_port,
|
276
|
+
helo= inbox.email_address.match(/@(.+)/)[1],
|
277
|
+
user= access_details.secure_smtp_username,
|
278
|
+
secret= access_details.secure_smtp_password,
|
279
|
+
authtype= :plain
|
280
|
+
) do |smtp|
|
281
|
+
message = <<EOF
|
282
|
+
Subject: SMTP test
|
283
|
+
|
284
|
+
This is my body
|
285
|
+
EOF
|
286
|
+
smtp.send_message message, inbox.email_address, inbox.email_address
|
287
|
+
smtp.finish
|
288
|
+
end
|
289
|
+
|
290
|
+
```
|
246
291
|
|
247
292
|
### Receive emails
|
248
293
|
|
@@ -250,11 +295,23 @@ To read already existing emails use the [Email Controller](https://ruby.mailslur
|
|
250
295
|
You can use MailSlurp to wait for at least 1 unread email in an inbox and return it.
|
251
296
|
If a timeout is exceeded it will throw an error instead:
|
252
297
|
|
253
|
-
|
298
|
+
```ruby
|
299
|
+
wait_for_controller = MailSlurpClient::WaitForControllerApi.new
|
300
|
+
wait_options = {
|
301
|
+
inbox_id: inbox.id,
|
302
|
+
timeout: 120000,
|
303
|
+
unread_only: true
|
304
|
+
}
|
305
|
+
email = wait_for_controller.wait_for_latest_email(wait_options)
|
306
|
+
assert_match /Welcome/, email.body
|
307
|
+
```
|
254
308
|
|
255
309
|
### Extract email content
|
256
310
|
|
257
|
-
|
311
|
+
```ruby
|
312
|
+
code = email.body.match(/Your code is: ([0-9]{6})/)[1]
|
313
|
+
assert_equal code, '123456'
|
314
|
+
```
|
258
315
|
|
259
316
|
To parse an email and extract content use regex patterns like so:
|
260
317
|
|