Skip to content

Commit 13883d1

Browse files
committed
fix readme
1 parent 76789ba commit 13883d1

File tree

1 file changed

+55
-43
lines changed

1 file changed

+55
-43
lines changed

README.md

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![downloads](https://shields.io/gem/dt/mailtrap)](https://rubygems.org/gems/mailtrap)
55
[![license](https://shields.io/badge/license-MIT-green)](https://opensource.org/licenses/MIT)
66

7-
# Mailtrap Ruby client - Official
7+
# Official Mailtrap Ruby client
88

99
## Prerequisites
1010

@@ -17,30 +17,32 @@ To get the most out of this official Mailtrap.io Ruby SDK:
1717

1818
This Ruby gem offers integration with the [official API](https://api-docs.mailtrap.io/) for [Mailtrap](https://mailtrap.io).
1919

20-
Quickly integrate Mailtrap with your Ruby application.
20+
Quickly add email sending functionality to your Ruby application with Mailtrap.
21+
22+
(This client uses API v2, for v1 refer to [this documentation](https://mailtrap.docs.apiary.io/))
2123

2224
Currently, with this SDK you can:
2325

2426
* **Email API/SMTP**
25-
* Send an email (Transactional and Bulk streams)
26-
* Send an email with a template
27-
* Send a batch of emails (Transactional and Bulk streams)
27+
* Send an email (Transactional and Bulk streams)
28+
* Send an email with a template
29+
* Send a batch of emails (Transactional and Bulk streams)
2830
* **Email Sandbox (Testing)**
29-
* Send an email
30-
* Send an email with a template
31-
* Message management
32-
* Inbox management
33-
* Project management
31+
* Send an email
32+
* Send an email with a template
33+
* Message management
34+
* Inbox management
35+
* Project management
3436
* **Contact management**
35-
* Contacts CRUD
36-
* Lists CRUD
37-
* Contact fields CRUD
37+
* Contacts CRUD
38+
* Lists CRUD
39+
* Contact fields CRUD
3840
* **General**
39-
* Templates CRUD
40-
* Suppressions management (find and delete)
41-
* Account access management
42-
* Permissions management
43-
* List accounts you have access to
41+
* Templates CRUD
42+
* Suppressions management (find and delete)
43+
* Account access management
44+
* Permissions management
45+
* List accounts you have access to
4446

4547
## Installation
4648

@@ -52,15 +54,11 @@ gem 'mailtrap'
5254

5355
And then execute:
5456

55-
```bash
56-
bundle install
57-
```
57+
$ bundle install
5858

5959
Or install it yourself as:
6060

61-
```bash
62-
gem install mailtrap
63-
```
61+
$ gem install mailtrap
6462

6563
## Usage
6664

@@ -72,18 +70,13 @@ require 'mailtrap'
7270
# For this example to work, you need to set up a sending domain,
7371
# and obtain a token that is authorized to send from the domain.
7472

75-
TOKEN = "<YOUR-TOKEN-HERE>"
76-
SENDER_EMAIL = "<[email protected]>"
77-
RECIPIENT_EMAIL = "<[email protected]>"
78-
79-
client = Mailtrap::Client.new(api_key: TOKEN)
80-
sender = { name: "Mailtrap Test", email: SENDER_EMAIL }
73+
client = Mailtrap::Client.new(api_key: 'your-api-key')
8174

8275
client.send(
83-
from: sender,
84-
to: [{ email: RECIPIENT_EMAIL }],
85-
subject: "Hello from Mailtrap!",
86-
text: "Welcome to Mailtrap Sending!"
76+
from: { email: '[email protected]', name: 'Mailtrap Test' },
77+
to: [{ email: '[email protected]' }],
78+
subject: 'Hello from Mailtrap!',
79+
text: 'Welcome to Mailtrap Sending!'
8780
)
8881
```
8982

@@ -92,12 +85,12 @@ client.send(
9285
```ruby
9386
# config/environments/production.rb
9487
config.action_mailer.delivery_method = :mailtrap
95-
config.action_mailer.mailtrap_settings = {
96-
api_key: 'your-api-key'
97-
}
9888

9989
# Set the MAILTRAP_API_KEY environment variable
100-
# using your hosting solution.
90+
# using your hosting solution, or customize the settings:
91+
config.action_mailer.mailtrap_settings = {
92+
api_key: ENV.fetch('MAILTRAP_API_KEY')
93+
}
10194
```
10295

10396
### Pure Ruby
@@ -214,13 +207,26 @@ require 'mailtrap'
214207
client = Mailtrap::Client.new(api_key: 'your-api-key')
215208
templates = Mailtrap::EmailTemplatesAPI.new(3229, client)
216209

217-
templates.create(
210+
# Create a new email template
211+
email_template = templates.create(
218212
name: 'Welcome Email',
219213
subject: 'Welcome to Mailtrap!',
220214
body_html: '<h1>Hello</h1>',
221215
body_text: 'Hello',
222216
category: 'welcome'
223217
)
218+
219+
# Get all templates
220+
templates.list
221+
222+
# Get a specific template
223+
templates.get(email_template.id)
224+
225+
# Update a template
226+
templates.update(email_template.id, name: 'Welcome Updated')
227+
228+
# Delete a template
229+
templates.delete(email_template.id)
224230
```
225231

226232
### Contacts API
@@ -253,7 +259,7 @@ contact = contacts.create(
253259
# Get contact
254260
contact = contacts.get(contact.id)
255261

256-
# Update contact
262+
# Update contact (upsert by ID or email)
257263
contacts.upsert(
258264
contact.id,
259265
@@ -263,6 +269,12 @@ contacts.upsert(
263269
# List contacts
264270
contacts.list
265271

272+
# Add contact to lists
273+
contacts.add_to_lists(contact.id, [list.id])
274+
275+
# Remove contact from lists
276+
contacts.remove_from_lists(contact.id, [list.id])
277+
266278
# Delete contact
267279
contacts.delete(contact.id)
268280
```
@@ -281,14 +293,14 @@ ActionMailer::Base.add_delivery_method :mailtrap_sandbox, Mailtrap::ActionMailer
281293
# config/environments/production.rb
282294
config.action_mailer.delivery_method = :mailtrap
283295
config.action_mailer.mailtrap_settings = {
284-
api_key: 'your-api-key'
296+
api_key: ENV.fetch('MAILTRAP_API_KEY')
285297
}
286298
config.action_mailer.mailtrap_bulk_settings = {
287-
api_key: 'your-api-key',
299+
api_key: ENV.fetch('MAILTRAP_API_KEY'),
288300
bulk: true
289301
}
290302
config.action_mailer.mailtrap_sandbox_settings = {
291-
api_key: 'your-api-key',
303+
api_key: ENV.fetch('MAILTRAP_API_KEY'),
292304
sandbox: true,
293305
inbox_id: 12
294306
}

0 commit comments

Comments
 (0)