Repository navigation
Expand file tree
/
Copy pathsuppressions_api.rb
More file actions
49 lines (43 loc) · 1.52 KB
/
Copy pathsuppressions_api.rb
File metadata and controls
49 lines (43 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'mailtrap'
account_id = 3229
client = Mailtrap::Client.new(api_key: 'your-api-key')
suppressions = Mailtrap::SuppressionsAPI.new(account_id, client)
# Set your API credentials as environment variables
# export MAILTRAP_API_KEY='your-api-key'
# export MAILTRAP_ACCOUNT_ID=your-account-id
#
# suppressions = Mailtrap::SuppressionsAPI.new
# Get all suppressions
suppressions.list
# =>
# [
# #<struct Mailtrap::Suppression
# id="64d71bf3-1276-417b-86e1-8e66f138acfe",
# type="unsubscription",
# created_at="2024-12-26T09:40:44.161Z",
# email="recipient@example.com",
# sending_stream="transactional",
# domain_name="example.com",
# message_bounce_category="",
# message_category="Welcome email",
# message_client_ip="123.123.123.123",
# message_created_at="2024-12-26T07:10:00.889Z",
# message_esp_response="",
# message_esp_server_type="",
# message_outgoing_ip="1.1.1.1",
# message_recipient_mx_name="Other Providers",
# message_sender_email="hello@sender.com",
# message_subject="Welcome!">
# ]
# Get suppressions for the email
suppressions.list(email: 'recipient@example.com')
# Add an email to the suppression list.
# `type` is optional and defaults to 'manual import'.
suppression = suppressions.create(
email: 'recipient@example.com',
domain_id: 12_345,
sending_stream: 'transactional'
)
# => #<struct Mailtrap::Suppression id="64d71bf3-1276-417b-86e1-8e66f138acfe", type="manual import", ...>
# Delete a suppression
suppressions.delete(suppression.id)