Skip to content

Commit fe7b7b8

Browse files
committed
updated batch methods examples and descriptions
1 parent 2471f10 commit fe7b7b8

File tree

2 files changed

+68
-57
lines changed

2 files changed

+68
-57
lines changed

lib/mailtrap/client.rb

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -52,58 +52,63 @@ def initialize( # rubocop:disable Metrics/ParameterLists
5252
end
5353

5454
# Sends a batch of emails.
55-
# @example
56-
# mail = Mailtrap::Mail::Base.new(
57-
# from: { email: '[email protected]', name: 'Mailtrap Test' },
58-
# reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
59-
# template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c',
60-
# template_variables: {
61-
# 'user_name' => 'John Doe'
62-
# }
63-
# )
55+
# @example Sending batch emails using helpers
56+
# mail = Mailtrap::Mail.batch_base_from_template(
57+
# from: { email: '[email protected]', name: 'Mailtrap Test' },
58+
# reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
59+
# template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c',
60+
# template_variables: {
61+
# 'user_name' => 'John Doe'
62+
# }
63+
# )
6464
#
65-
# client.send_batch(mail, [
66-
# Mailtrap::Mail::Base.new(
67-
# to: [
68-
# { email: '[email protected]', name: 'recipient1' }
69-
# ]
70-
# ),
71-
# Mailtrap::Mail::Base.new(
72-
# to: [
73-
# { email: '[email protected]', name: 'recipient2' }
74-
# ],
75-
# template_variables: {
76-
# 'user_name' => 'John Doe 1',
77-
# 'user_name2' => 'John Doe 2'
78-
# }
79-
# )
80-
# ])
65+
# client.send_batch(
66+
# mail,
67+
# [
68+
# Mailtrap::Mail.from_content(
69+
# to: [
70+
# { email: '[email protected]', name: 'recipient1' }
71+
# ]
72+
# ),
73+
# Mailtrap::Mail.from_template(
74+
# to: [
75+
# { email: '[email protected]', name: 'recipient2' }
76+
# ],
77+
# template_variables: {
78+
# 'user_name' => 'John Doe 1',
79+
# 'user_name2' => 'John Doe 2'
80+
# }
81+
# )
82+
# ]
83+
# )
8184
#
82-
# @example
83-
# client.send_batch({
84-
# from: { email: '[email protected]', name: 'Mailtrap Test' },
85-
# reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
86-
# template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c',
87-
# template_variables: {
88-
# 'user_name' => 'John Doe'
89-
# },
90-
# },
91-
# [
92-
# {
93-
# to: [
94-
# { email: '[email protected]', name: 'recipient1' }
95-
# ]
96-
# },
97-
# {
98-
# to: [
99-
# { email: '[email protected]', name: 'recipient2' }
100-
# ],
101-
# template_variables: {
102-
# 'user_name' => 'John Doe 1',
103-
# 'user_name2' => 'John Doe 2'
104-
# }
105-
# }
106-
# ])
85+
# @example Sending batch emails using plain hashes
86+
# client.send_batch(
87+
# {
88+
# from: { email: '[email protected]', name: 'Mailtrap Test' },
89+
# reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
90+
# template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c',
91+
# template_variables: {
92+
# 'user_name' => 'John Doe'
93+
# }
94+
# },
95+
# [
96+
# {
97+
# to: [
98+
# { email: '[email protected]', name: 'recipient1' }
99+
# ]
100+
# },
101+
# {
102+
# to: [
103+
# { email: '[email protected]', name: 'recipient2' }
104+
# ],
105+
# template_variables: {
106+
# 'user_name' => 'John Doe 1',
107+
# 'user_name2' => 'John Doe 2'
108+
# }
109+
# }
110+
# ]
111+
# )
107112
# @param base [#to_json] The base email configuration for the batch.
108113
# @param requests [Array<#to_json>] Array of individual email requests.
109114
# @return [Hash] The JSON response from the API.

lib/mailtrap/mail.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,20 @@ def from_content( # rubocop:disable Metrics/ParameterLists
117117
)
118118
end
119119

120-
# Builds a mail object that will be sent using a pre-defined email
121-
# template. The template content (subject, text, html, category) is
122-
# defined in the Mailtrap dashboard and referenced by the template_uuid.
123-
# Template variables can be passed to customize the template content.
120+
# Builds a base mail object for batch sending using a pre-defined email template.
121+
# This "base" defines shared properties (such as sender, reply-to, template UUID, and template variables)
122+
# that will be used as defaults for all emails in the batch. Individual batch requests can override these values.
123+
# Use this method when you want to send multiple emails with similar content, leveraging a template defined in the Mailtrap dashboard. # rubocop:disable Layout/LineLength
124+
# Template variables can be passed to customize the template content for all recipients, and can be overridden per request. # rubocop:disable Layout/LineLength
124125
# @example
125-
# mail = Mailtrap::Mail.batch_base_from_template(
126+
# base_mail = Mailtrap::Mail.batch_base_from_template(
126127
# from: { email: '[email protected]', name: 'Mailtrap Test' },
127128
# template_uuid: '2f45b0aa-bbed-432f-95e4-e145e1965ba2',
128129
# template_variables: {
129130
# 'user_name' => 'John Doe'
130131
# }
131132
# )
133+
# # Use base_mail as the base for batch sending with Mailtrap::Client#send_batch
132134
def batch_base_from_template( # rubocop:disable Metrics/ParameterLists
133135
from: nil,
134136
reply_to: nil,
@@ -149,13 +151,17 @@ def batch_base_from_template( # rubocop:disable Metrics/ParameterLists
149151
)
150152
end
151153

152-
# Builds a mail object with content including subject, text, html, and category.
154+
# Builds a base mail object for batch sending with custom content (subject, text, html, category).
155+
# This "base" defines shared properties for all emails in the batch, such as sender, subject, and body.
156+
# Individual batch requests can override these values as needed.
157+
# Use this method when you want to send multiple emails with similar custom content to different recipients.
153158
# @example
154-
# mail = Mailtrap::Mail.batch_base_from_content(
159+
# base_mail = Mailtrap::Mail.batch_base_from_content(
155160
# from: { email: '[email protected]', name: 'Mailtrap Test' },
156161
# subject: 'You are awesome!',
157162
# text: 'Congrats for sending test email with Mailtrap!'
158163
# )
164+
# # Use base_mail as the base for batch sending with Mailtrap::Client#send_batch
159165
def batch_base_from_content( # rubocop:disable Metrics/ParameterLists
160166
from: nil,
161167
reply_to: nil,

0 commit comments

Comments
 (0)