mailtrap 2.5.0 → 2.7.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/.coderabbit.yaml +10 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +68 -53
- data/README.md +75 -29
- data/lib/mailtrap/account.rb +16 -0
- data/lib/mailtrap/accounts_api.rb +33 -0
- data/lib/mailtrap/client.rb +44 -28
- data/lib/mailtrap/contact.rb +0 -5
- data/lib/mailtrap/contact_field.rb +1 -6
- data/lib/mailtrap/contact_import.rb +1 -6
- data/lib/mailtrap/contact_list.rb +1 -6
- data/lib/mailtrap/email_template.rb +1 -6
- data/lib/mailtrap/inbox.rb +57 -0
- data/lib/mailtrap/inboxes_api.rb +98 -0
- data/lib/mailtrap/project.rb +20 -0
- data/lib/mailtrap/projects_api.rb +77 -0
- data/lib/mailtrap/sandbox_attachment.rb +34 -0
- data/lib/mailtrap/sandbox_attachments_api.rb +51 -0
- data/lib/mailtrap/sandbox_message.rb +59 -0
- data/lib/mailtrap/sandbox_messages_api.rb +155 -0
- data/lib/mailtrap/sending_domain.rb +42 -0
- data/lib/mailtrap/sending_domains_api.rb +67 -0
- data/lib/mailtrap/suppression.rb +1 -6
- data/lib/mailtrap/version.rb +1 -1
- data/lib/mailtrap.rb +6 -0
- metadata +16 -3
|
@@ -5,10 +5,5 @@ module Mailtrap
|
|
|
5
5
|
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/6ec7a37234af2-contact-list
|
|
6
6
|
# @attr_reader id [Integer] The contact list ID
|
|
7
7
|
# @attr_reader name [String] The name of the contact list
|
|
8
|
-
ContactList = Struct.new(:id, :name, keyword_init: true)
|
|
9
|
-
# @return [Hash] The contact list attributes as a hash
|
|
10
|
-
def to_h
|
|
11
|
-
super.compact
|
|
12
|
-
end
|
|
13
|
-
end
|
|
8
|
+
ContactList = Struct.new(:id, :name, keyword_init: true)
|
|
14
9
|
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Inbox
|
|
5
|
+
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project
|
|
6
|
+
# @attr_reader id [Integer] The inbox ID
|
|
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
|
+
)
|
|
57
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'inbox'
|
|
5
|
+
|
|
6
|
+
module Mailtrap
|
|
7
|
+
class InboxesAPI
|
|
8
|
+
include BaseAPI
|
|
9
|
+
|
|
10
|
+
self.supported_options = %i[name]
|
|
11
|
+
self.response_class = Inbox
|
|
12
|
+
|
|
13
|
+
# Lists all Inboxes for the account
|
|
14
|
+
# @return [Array<Inbox>] Array of Inboxes
|
|
15
|
+
# @!macro api_errors
|
|
16
|
+
def list
|
|
17
|
+
base_list
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Retrieves a specific inbox
|
|
21
|
+
# @param inbox_id [Integer] The inbox identifier
|
|
22
|
+
# @return [Inbox] Inbox object
|
|
23
|
+
# @!macro api_errors
|
|
24
|
+
def get(inbox_id)
|
|
25
|
+
base_get(inbox_id)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Creates a new inbox
|
|
29
|
+
# @param [Hash] options The parameters to create
|
|
30
|
+
# @option options [String] :name The inbox name
|
|
31
|
+
# @return [Inbox] Created inbox object
|
|
32
|
+
# @!macro api_errors
|
|
33
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
34
|
+
def create(options)
|
|
35
|
+
validate_options!(options, supported_options + [:project_id])
|
|
36
|
+
response = client.post("/api/accounts/#{account_id}/projects/#{options[:project_id]}/inboxes",
|
|
37
|
+
wrap_request(options))
|
|
38
|
+
handle_response(response)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Deletes an inbox
|
|
42
|
+
# @param inbox_id [Integer] The Inbox identifier
|
|
43
|
+
# @return nil
|
|
44
|
+
# @!macro api_errors
|
|
45
|
+
def delete(inbox_id)
|
|
46
|
+
base_delete(inbox_id)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Updates an existing Inbox
|
|
50
|
+
# @param inbox_id [Integer] The Inbox identifier
|
|
51
|
+
# @param [Hash] options The parameters to update
|
|
52
|
+
# @option options [String] :name The inbox name
|
|
53
|
+
# @option options [String] :email_username The inbox email username
|
|
54
|
+
# @return [Inbox] Updated Inbox object
|
|
55
|
+
# @!macro api_errors
|
|
56
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
57
|
+
def update(inbox_id, options)
|
|
58
|
+
base_update(inbox_id, options, supported_options + [:email_username])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Delete all messages (emails) from Inbox
|
|
62
|
+
# @param inbox_id [Integer] The Inbox identifier
|
|
63
|
+
# @return [Inbox] Updated Inbox object
|
|
64
|
+
# @!macro api_errors
|
|
65
|
+
def clean(inbox_id)
|
|
66
|
+
response = client.patch("#{base_path}/#{inbox_id}/clean")
|
|
67
|
+
handle_response(response)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Mark all messages in the inbox as read
|
|
71
|
+
# @param inbox_id [Integer] The Inbox identifier
|
|
72
|
+
# @return [Inbox] Updated Inbox object
|
|
73
|
+
# @!macro api_errors
|
|
74
|
+
def mark_as_read(inbox_id)
|
|
75
|
+
response = client.patch("#{base_path}/#{inbox_id}/all_read")
|
|
76
|
+
handle_response(response)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Reset SMTP credentials of the inbox
|
|
80
|
+
# @param inbox_id [Integer] The Inbox identifier
|
|
81
|
+
# @return [Inbox] Updated Inbox object
|
|
82
|
+
# @!macro api_errors
|
|
83
|
+
def reset_credentials(inbox_id)
|
|
84
|
+
response = client.patch("#{base_path}/#{inbox_id}/reset_credentials")
|
|
85
|
+
handle_response(response)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def wrap_request(options)
|
|
91
|
+
{ inbox: options }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def base_path
|
|
95
|
+
"/api/accounts/#{account_id}/inboxes"
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Project
|
|
5
|
+
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project
|
|
6
|
+
# @attr_reader id [Integer] The project ID
|
|
7
|
+
# @attr_reader name [String] The project name
|
|
8
|
+
# @attr_reader share_links [Hash] Admin and viewer share links
|
|
9
|
+
# @attr_reader inboxes [Array<Mailtrap::Inbox>] Array of inboxes
|
|
10
|
+
# @attr_reader permissions [Hash] List of permissions
|
|
11
|
+
#
|
|
12
|
+
Project = Struct.new(
|
|
13
|
+
:id,
|
|
14
|
+
:name,
|
|
15
|
+
:share_links,
|
|
16
|
+
:inboxes,
|
|
17
|
+
:permissions,
|
|
18
|
+
keyword_init: true
|
|
19
|
+
)
|
|
20
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'project'
|
|
5
|
+
require_relative 'inbox'
|
|
6
|
+
|
|
7
|
+
module Mailtrap
|
|
8
|
+
class ProjectsAPI
|
|
9
|
+
include BaseAPI
|
|
10
|
+
|
|
11
|
+
self.supported_options = %i[name]
|
|
12
|
+
|
|
13
|
+
self.response_class = Project
|
|
14
|
+
|
|
15
|
+
# Lists all projects for the account
|
|
16
|
+
# @return [Array<Project>] Array of projects
|
|
17
|
+
# @!macro api_errors
|
|
18
|
+
def list
|
|
19
|
+
base_list
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Retrieves a specific project
|
|
23
|
+
# @param project_id [Integer] The project ID
|
|
24
|
+
# @return [Project] Project object
|
|
25
|
+
# @!macro api_errors
|
|
26
|
+
def get(project_id)
|
|
27
|
+
base_get(project_id)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Creates a new project
|
|
31
|
+
# @param [Hash] options The parameters to create
|
|
32
|
+
# @option options [String] :name The project name
|
|
33
|
+
# @return [Project] Created project object
|
|
34
|
+
# @!macro api_errors
|
|
35
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
36
|
+
def create(options)
|
|
37
|
+
base_create(options)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Updates an existing project
|
|
41
|
+
# @param project_id [Integer] The project ID
|
|
42
|
+
# @param [Hash] options The parameters to update
|
|
43
|
+
# @return [Project] Updated project object
|
|
44
|
+
# @!macro api_errors
|
|
45
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
46
|
+
def update(project_id, options)
|
|
47
|
+
base_update(project_id, options)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Deletes a project
|
|
51
|
+
# @param project_id [Integer] The project ID
|
|
52
|
+
# @return nil
|
|
53
|
+
# @!macro api_errors
|
|
54
|
+
def delete(project_id)
|
|
55
|
+
base_delete(project_id)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def handle_response(response)
|
|
61
|
+
build_entity(
|
|
62
|
+
response.merge(
|
|
63
|
+
inboxes: response[:inboxes]&.map { |inbox| build_entity(inbox, Mailtrap::Inbox) }
|
|
64
|
+
),
|
|
65
|
+
response_class
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def base_path
|
|
70
|
+
"/api/accounts/#{account_id}/projects"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def wrap_request(options)
|
|
74
|
+
{ project: options }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for SandboxAttachment
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/email-sandbox/email-sandbox-api/attachments
|
|
6
|
+
# @attr_reader id [Integer] The attachment ID
|
|
7
|
+
# @attr_reader message_id [Integer] The message ID
|
|
8
|
+
# @attr_reader filename [String] The attachment filename
|
|
9
|
+
# @attr_reader attachment_type [String] The attachment type
|
|
10
|
+
# @attr_reader content_type [String] The attachment content type
|
|
11
|
+
# @attr_reader content_id [String] The attachment content ID
|
|
12
|
+
# @attr_reader transfer_encoding [String] The attachment transfer encoding
|
|
13
|
+
# @attr_reader attachment_size [Integer] The attachment size in bytes
|
|
14
|
+
# @attr_reader created_at [String] The attachment creation timestamp
|
|
15
|
+
# @attr_reader updated_at [String] The attachment update timestamp
|
|
16
|
+
# @attr_reader attachment_human_size [String] The attachment size in human-readable format
|
|
17
|
+
# @attr_reader download_path [String] The attachment download path
|
|
18
|
+
#
|
|
19
|
+
SandboxAttachment = Struct.new(
|
|
20
|
+
:id,
|
|
21
|
+
:message_id,
|
|
22
|
+
:filename,
|
|
23
|
+
:attachment_type,
|
|
24
|
+
:content_type,
|
|
25
|
+
:content_id,
|
|
26
|
+
:transfer_encoding,
|
|
27
|
+
:attachment_size,
|
|
28
|
+
:created_at,
|
|
29
|
+
:updated_at,
|
|
30
|
+
:attachment_human_size,
|
|
31
|
+
:download_path,
|
|
32
|
+
keyword_init: true
|
|
33
|
+
)
|
|
34
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'sandbox_attachment'
|
|
5
|
+
|
|
6
|
+
module Mailtrap
|
|
7
|
+
class SandboxAttachmentsAPI
|
|
8
|
+
include BaseAPI
|
|
9
|
+
|
|
10
|
+
attr_reader :account_id, :inbox_id, :sandbox_message_id, :client
|
|
11
|
+
|
|
12
|
+
self.response_class = SandboxAttachment
|
|
13
|
+
|
|
14
|
+
# @param account_id [Integer] The account ID
|
|
15
|
+
# @param inbox_id [Integer] The inbox ID
|
|
16
|
+
# @param sandbox_message_id [Integer] The message ID
|
|
17
|
+
# @param client [Mailtrap::Client] The client instance
|
|
18
|
+
# @raise [ArgumentError] If account_id is nil
|
|
19
|
+
# @raise [ArgumentError] If inbox_id is nil
|
|
20
|
+
def initialize(account_id, inbox_id, sandbox_message_id, client = Mailtrap::Client.new)
|
|
21
|
+
raise ArgumentError, 'inbox_id is required' if inbox_id.nil?
|
|
22
|
+
raise ArgumentError, 'sandbox_message_id is required' if sandbox_message_id.nil?
|
|
23
|
+
|
|
24
|
+
@inbox_id = inbox_id
|
|
25
|
+
@sandbox_message_id = sandbox_message_id
|
|
26
|
+
|
|
27
|
+
super(account_id, client)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Retrieves a specific sandbox attachment
|
|
31
|
+
# @param sandbox_attachment_id [Integer] The sandbox attachment ID
|
|
32
|
+
# @return [SandboxAttachment] Sandbox attachment object
|
|
33
|
+
# @!macro api_errors
|
|
34
|
+
def get(sandbox_attachment_id)
|
|
35
|
+
base_get(sandbox_attachment_id)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Lists all sandbox attachments for a message, limited up to 30 at once
|
|
39
|
+
# @return [Array<SandboxAttachment>] Array of sandbox attachment objects
|
|
40
|
+
# @!macro api_errors
|
|
41
|
+
def list
|
|
42
|
+
base_list
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def base_path
|
|
48
|
+
"/api/accounts/#{account_id}/inboxes/#{inbox_id}/messages/#{sandbox_message_id}/attachments"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Sandbox Message
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/email-sandbox/email-sandbox-api/messages
|
|
6
|
+
# @attr_reader id [Integer] The message ID
|
|
7
|
+
# @attr_reader inbox_id [Integer] The inbox ID
|
|
8
|
+
# @attr_reader subject [String] The message subject
|
|
9
|
+
# @attr_reader sent_at [String] The timestamp when the message was sent
|
|
10
|
+
# @attr_reader from_email [String] The sender's email address
|
|
11
|
+
# @attr_reader from_name [String] The sender's name
|
|
12
|
+
# @attr_reader to_email [String] The recipient's email address
|
|
13
|
+
# @attr_reader to_name [String] The recipient's name
|
|
14
|
+
# @attr_reader email_size [Integer] The size of the email in bytes
|
|
15
|
+
# @attr_reader is_read [Boolean] Whether the message has been read
|
|
16
|
+
# @attr_reader created_at [String] The timestamp when the message was created
|
|
17
|
+
# @attr_reader updated_at [String] The timestamp when the message was last updated
|
|
18
|
+
# @attr_reader html_body_size [Integer] The size of the HTML body in bytes
|
|
19
|
+
# @attr_reader text_body_size [Integer] The size of the text body in bytes
|
|
20
|
+
# @attr_reader human_size [String] The human-readable size of the email
|
|
21
|
+
# @attr_reader html_path [String] The path to the HTML version of the email
|
|
22
|
+
# @attr_reader txt_path [String] The path to the text version of the email
|
|
23
|
+
# @attr_reader raw_path [String] The path to the raw version of the email
|
|
24
|
+
# @attr_reader download_path [String] The path to download the email
|
|
25
|
+
# @attr_reader html_source_path [String] The path to the HTML source of the email
|
|
26
|
+
# @attr_reader blacklists_report_info [Boolean] Information about blacklists report
|
|
27
|
+
# @attr_reader smtp_information [Hash] Information about SMTP
|
|
28
|
+
#
|
|
29
|
+
SandboxMessage = Struct.new(
|
|
30
|
+
:id,
|
|
31
|
+
:inbox_id,
|
|
32
|
+
:subject,
|
|
33
|
+
:sent_at,
|
|
34
|
+
:from_email,
|
|
35
|
+
:from_name,
|
|
36
|
+
:to_email,
|
|
37
|
+
:to_name,
|
|
38
|
+
:email_size,
|
|
39
|
+
:is_read,
|
|
40
|
+
:created_at,
|
|
41
|
+
:updated_at,
|
|
42
|
+
:html_body_size,
|
|
43
|
+
:text_body_size,
|
|
44
|
+
:human_size,
|
|
45
|
+
:html_path,
|
|
46
|
+
:txt_path,
|
|
47
|
+
:raw_path,
|
|
48
|
+
:download_path,
|
|
49
|
+
:html_source_path,
|
|
50
|
+
:blacklists_report_info,
|
|
51
|
+
:smtp_information,
|
|
52
|
+
keyword_init: true
|
|
53
|
+
) do
|
|
54
|
+
# @return [Boolean] Whether the message has been read
|
|
55
|
+
def read?
|
|
56
|
+
is_read
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'sandbox_message'
|
|
5
|
+
|
|
6
|
+
module Mailtrap
|
|
7
|
+
class SandboxMessagesAPI
|
|
8
|
+
include BaseAPI
|
|
9
|
+
|
|
10
|
+
attr_reader :account_id, :inbox_id, :client
|
|
11
|
+
|
|
12
|
+
self.supported_options = %i[is_read]
|
|
13
|
+
|
|
14
|
+
self.response_class = SandboxMessage
|
|
15
|
+
|
|
16
|
+
# @param account_id [Integer] The account ID
|
|
17
|
+
# @param inbox_id [Integer] The inbox ID
|
|
18
|
+
# @param client [Mailtrap::Client] The client instance
|
|
19
|
+
# @raise [ArgumentError] If account_id is nil
|
|
20
|
+
# @raise [ArgumentError] If inbox_id is nil
|
|
21
|
+
def initialize(account_id, inbox_id, client = Mailtrap::Client.new)
|
|
22
|
+
raise ArgumentError, 'inbox_id is required' if inbox_id.nil?
|
|
23
|
+
|
|
24
|
+
@inbox_id = inbox_id
|
|
25
|
+
|
|
26
|
+
super(account_id, client)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Retrieves a specific sandbox message from inbox
|
|
30
|
+
# @param message_id [Integer] The sandbox message ID
|
|
31
|
+
# @return [SandboxMessage] Sandbox message object
|
|
32
|
+
# @!macro api_errors
|
|
33
|
+
def get(message_id)
|
|
34
|
+
base_get(message_id)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Deletes a sandbox message
|
|
38
|
+
# @param message_id [Integer] The sandbox message ID
|
|
39
|
+
# @return [SandboxMessage] Deleted Sandbox message object
|
|
40
|
+
# @!macro api_errors
|
|
41
|
+
def delete(message_id)
|
|
42
|
+
base_delete(message_id)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Updates an existing sandbox message
|
|
46
|
+
# @param message_id [Integer] The sandbox message ID
|
|
47
|
+
# @param is_read [Boolean]
|
|
48
|
+
# @return [SandboxMessage] Updated Sandbox message object
|
|
49
|
+
# @!macro api_errors
|
|
50
|
+
def mark_as_read(message_id, is_read: true)
|
|
51
|
+
base_update(message_id, { is_read: is_read })
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Lists all sandbox messages for the account, limited up to 30 at once
|
|
55
|
+
# @param search [String] Search query string. Matches subject, to_email, and to_name.
|
|
56
|
+
# @param last_id [Integer] If specified, a page of records before last_id is returned.
|
|
57
|
+
# Overrides page if both are given.
|
|
58
|
+
# @param page [Integer] Page number for paginated results.
|
|
59
|
+
# @return [Array<SandboxMessage>] Array of sandbox message objects
|
|
60
|
+
# @!macro api_errors
|
|
61
|
+
def list(search: nil, last_id: nil, page: nil)
|
|
62
|
+
raise ArgumentError, 'Provide either last_id or page, not both' unless last_id.nil? || page.nil?
|
|
63
|
+
|
|
64
|
+
query_params = {}
|
|
65
|
+
query_params[:search] = search unless search.nil?
|
|
66
|
+
query_params[:last_id] = last_id unless last_id.nil?
|
|
67
|
+
query_params[:page] = page unless page.nil?
|
|
68
|
+
|
|
69
|
+
base_list(query_params)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Forward message to an email address.
|
|
73
|
+
# @param message_id [Integer] The sandbox message ID
|
|
74
|
+
# @param email [String] The email to forward sandbox message to
|
|
75
|
+
# @return [String] Forwarded message confirmation
|
|
76
|
+
# @!macro api_errors
|
|
77
|
+
def forward_message(message_id, email:)
|
|
78
|
+
client.post("#{base_path}/#{message_id}/forward", { email: email })
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Get message spam score
|
|
82
|
+
# @param message_id [Integer] The sandbox message ID
|
|
83
|
+
# @return [Hash] Spam report
|
|
84
|
+
# @!macro api_errors
|
|
85
|
+
def spam_score(message_id)
|
|
86
|
+
client.get("#{base_path}/#{message_id}/spam_report")
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Get message HTML analysis
|
|
90
|
+
# @param message_id [Integer] The sandbox message ID
|
|
91
|
+
# @return [Hash] brief HTML report
|
|
92
|
+
# @!macro api_errors
|
|
93
|
+
def html_analysis(message_id)
|
|
94
|
+
client.get("#{base_path}/#{message_id}/analyze")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Get text message
|
|
98
|
+
# @param message_id [Integer] The sandbox message ID
|
|
99
|
+
# @return [String] text email body
|
|
100
|
+
# @!macro api_errors
|
|
101
|
+
def text_body(message_id)
|
|
102
|
+
client.get("#{base_path}/#{message_id}/body.txt")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Get raw message
|
|
106
|
+
# @param message_id [Integer] The sandbox message ID
|
|
107
|
+
# @return [String] raw email body
|
|
108
|
+
# @!macro api_errors
|
|
109
|
+
def raw_body(message_id)
|
|
110
|
+
client.get("#{base_path}/#{message_id}/body.raw")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Get message source
|
|
114
|
+
# @param message_id [Integer] The sandbox message ID
|
|
115
|
+
# @return [String] HTML source of a message.
|
|
116
|
+
# @!macro api_errors
|
|
117
|
+
def html_source(message_id)
|
|
118
|
+
client.get("#{base_path}/#{message_id}/body.htmlsource")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Get formatted HTML email body. Not applicable for plain text emails.
|
|
122
|
+
# @param message_id [Integer] The sandbox message ID
|
|
123
|
+
# @return [String] message body in html format.
|
|
124
|
+
# @!macro api_errors
|
|
125
|
+
def html_body(message_id)
|
|
126
|
+
client.get("#{base_path}/#{message_id}/body.html")
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Get message as EML
|
|
130
|
+
# @param message_id [Integer] The sandbox message ID
|
|
131
|
+
# @return [String] mail message body in EML format.
|
|
132
|
+
# @!macro api_errors
|
|
133
|
+
def eml_body(message_id)
|
|
134
|
+
client.get("#{base_path}/#{message_id}/body.eml")
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Get mail headers
|
|
138
|
+
# @param message_id [Integer] The sandbox message ID
|
|
139
|
+
# @return [Hash] mail headers of the message.
|
|
140
|
+
# @!macro api_errors
|
|
141
|
+
def mail_headers(message_id)
|
|
142
|
+
client.get("#{base_path}/#{message_id}/mail_headers")
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
private
|
|
146
|
+
|
|
147
|
+
def base_path
|
|
148
|
+
"/api/accounts/#{account_id}/inboxes/#{inbox_id}/messages"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def wrap_request(options)
|
|
152
|
+
{ message: options }
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Sending Domain
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/management/sending-domains
|
|
6
|
+
# @attr_reader id [Integer] The sending domain ID
|
|
7
|
+
# @attr_reader domain_name [String] The sending domain name
|
|
8
|
+
# @attr_reader demo [Boolean] Whether the sending domain is a demo domain
|
|
9
|
+
# @attr_reader compliance_status [String] The compliance status of the sending 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 sending 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 auto_unsubscribe_link_enabled [Boolean] Whether auto unsubscribe link is enabled
|
|
16
|
+
# @attr_reader custom_domain_tracking_enabled [Boolean] Whether custom domain tracking is enabled
|
|
17
|
+
# @attr_reader health_alerts_enabled [Boolean] Whether health alerts are enabled
|
|
18
|
+
# @attr_reader critical_alerts_enabled [Boolean] Whether critical alerts are enabled
|
|
19
|
+
# @attr_reader alert_recipient_email [String, nil] The email address for alert recipients
|
|
20
|
+
# @attr_reader permissions [Hash] The permissions for the sending domain
|
|
21
|
+
#
|
|
22
|
+
SendingDomain = Struct.new(
|
|
23
|
+
:id,
|
|
24
|
+
:domain_name,
|
|
25
|
+
:demo,
|
|
26
|
+
:compliance_status,
|
|
27
|
+
:dns_verified,
|
|
28
|
+
:dns_verified_at,
|
|
29
|
+
:dns_records,
|
|
30
|
+
:open_tracking_enabled,
|
|
31
|
+
:click_tracking_enabled,
|
|
32
|
+
:auto_unsubscribe_link_enabled,
|
|
33
|
+
:custom_domain_tracking_enabled,
|
|
34
|
+
:health_alerts_enabled,
|
|
35
|
+
:critical_alerts_enabled,
|
|
36
|
+
:alert_recipient_email,
|
|
37
|
+
:permissions,
|
|
38
|
+
:created_at,
|
|
39
|
+
:updated_at,
|
|
40
|
+
keyword_init: true
|
|
41
|
+
)
|
|
42
|
+
end
|