Module: Mailtrap::Mail
- Defined in:
- lib/mailtrap/mail.rb,
lib/mailtrap/mail/base.rb,
lib/mailtrap/mail/from_template.rb
Overview
rubocop:disable Metrics/ModuleLength
Defined Under Namespace
Classes: Base, FromTemplate
Class Method Summary collapse
-
.batch_base_from_content(from: nil, reply_to: nil, attachments: [], headers: {}, custom_variables: {}, subject: nil, text: nil, html: nil, category: nil) ⇒ Object
Builds a base mail object for batch sending with custom content (subject, text, html, category).
-
.batch_base_from_template(from: nil, reply_to: nil, attachments: [], headers: {}, custom_variables: {}, template_uuid: nil, template_variables: {}) ⇒ Object
Builds a base mail object for batch sending using a pre-defined email template.
-
.from_content(from: nil, to: [], reply_to: nil, cc: [], bcc: [], attachments: [], headers: {}, custom_variables: {}, subject: nil, text: nil, html: nil, category: nil) ⇒ Object
Builds a mail object with content including subject, text, html, and category.
-
.from_message(message) ⇒ Mailtrap::Mail::Base
Builds a mail object from Mail::Message.
-
.from_template(from: nil, to: [], reply_to: nil, cc: [], bcc: [], attachments: [], headers: {}, custom_variables: {}, template_uuid: nil, template_variables: {}) ⇒ Object
Builds a mail object that will be sent using a pre-defined email template.
Class Method Details
.batch_base_from_content(from: nil, reply_to: nil, attachments: [], headers: {}, custom_variables: {}, subject: nil, text: nil, html: nil, category: nil) ⇒ Object
Builds a base mail object for batch sending with custom content (subject, text, html, category). This “base” defines shared properties for all emails in the batch, such as sender, subject, and body. Individual batch requests can override these values as needed. Use this method when you want to send multiple emails with similar custom content to different recipients.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/mailtrap/mail.rb', line 165 def batch_base_from_content( # rubocop:disable Metrics/ParameterLists from: nil, reply_to: nil, attachments: [], headers: {}, custom_variables: {}, subject: nil, text: nil, html: nil, category: nil ) Mailtrap::Mail::Base.new( from:, reply_to:, attachments:, headers:, custom_variables:, subject:, text:, html:, category: ) end |
.batch_base_from_template(from: nil, reply_to: nil, attachments: [], headers: {}, custom_variables: {}, template_uuid: nil, template_variables: {}) ⇒ Object
Builds a base mail object for batch sending using a pre-defined email template. This “base” defines shared properties (such as sender, reply-to, template UUID, and template variables) that will be used as defaults for all emails in the batch. Individual batch requests can override these values. 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 Template variables can be passed to customize the template content for all recipients, and can be overridden per request. # rubocop:disable Layout/LineLength
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/mailtrap/mail.rb', line 134 def batch_base_from_template( # rubocop:disable Metrics/ParameterLists from: nil, reply_to: nil, attachments: [], headers: {}, custom_variables: {}, template_uuid: nil, template_variables: {} ) Mailtrap::Mail::Base.new( from:, reply_to:, attachments:, headers:, custom_variables:, template_uuid:, template_variables: ) end |
.from_content(from: nil, to: [], reply_to: nil, cc: [], bcc: [], attachments: [], headers: {}, custom_variables: {}, subject: nil, text: nil, html: nil, category: nil) ⇒ Object
Builds a mail object with content including subject, text, html, and category.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mailtrap/mail.rb', line 90 def from_content( # rubocop:disable Metrics/ParameterLists from: nil, to: [], reply_to: nil, cc: [], bcc: [], attachments: [], headers: {}, custom_variables: {}, subject: nil, text: nil, html: nil, category: nil ) Mailtrap::Mail::Base.new( from:, to:, reply_to:, cc:, bcc:, attachments:, headers:, custom_variables:, subject:, text:, html:, category: ) end |
.from_message(message) ⇒ Mailtrap::Mail::Base
Builds a mail object from Mail::Message
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/mailtrap/mail.rb', line 192 def () Mailtrap::Mail::Base.new( from: prepare_addresses(['from']).first, to: prepare_addresses(['to']), cc: prepare_addresses(['cc']), bcc: prepare_addresses(['bcc']), subject: .subject, text: prepare_text_part(), html: prepare_html_part(), headers: prepare_headers(), attachments: (.), category: ['category']&.unparsed_value, custom_variables: ['custom_variables']&.unparsed_value, template_uuid: ['template_uuid']&.unparsed_value, template_variables: ['template_variables']&.unparsed_value ) end |
.from_template(from: nil, to: [], reply_to: nil, cc: [], bcc: [], attachments: [], headers: {}, custom_variables: {}, template_uuid: nil, template_variables: {}) ⇒ Object
Builds a mail object that will be sent using a pre-defined email template. The template content (subject, text, html, category) is defined in the Mailtrap dashboard and referenced by the template_uuid. Template variables can be passed to customize the template content.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mailtrap/mail.rb', line 54 def from_template( # rubocop:disable Metrics/ParameterLists from: nil, to: [], reply_to: nil, cc: [], bcc: [], attachments: [], headers: {}, custom_variables: {}, template_uuid: nil, template_variables: {} ) Mailtrap::Mail::Base.new( from:, to:, reply_to:, cc:, bcc:, attachments:, headers:, custom_variables:, template_uuid:, template_variables: ) end |