Table of Contents

Class SendEmailRequestBuilder

Namespace
Mailtrap.Emails.Requests
Assembly
Mailtrap.dll

A set of helper methods to streamline SendEmailRequest instance construction using fluent style.

public static class SendEmailRequestBuilder
Inheritance
SendEmailRequestBuilder

Methods

Attach(SendEmailRequest, params Attachment[])

Adds provided attachments to the Attachments collection of the request.

public static SendEmailRequest Attach(this SendEmailRequest request, params Attachment[] attachments)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
attachments Attachment[]

One or more Attachment objects to add to the request's Attachments collection.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Duplicates can be added by calling this method multiple times with the same Attachment object.

Exceptions

ArgumentNullException

When request or attachments is null.

Attach(SendEmailRequest, string, string, DispositionType?, string?, string?)

Adds provided attachment to the Attachments collection of the request.

public static SendEmailRequest Attach(this SendEmailRequest request, string content, string fileName, DispositionType? disposition = null, string? mimeType = null, string? contentId = null)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
content string

The Base64 encoded content of the attachment.

Required. Must be non-empty string.

fileName string

Attachment file name.

Required. Must be non-empty string.

disposition DispositionType

The attachment's content disposition, specifying how you would like the attachment to be displayed.

Optional. Defaults to Attachment if not specified explicitly.

mimeType string

Attachment MIME type identifier (e.g. "text/plain", "application/pdf", etc.)

Optional.

contentId string

The attachment's content ID.

Optional.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Duplicates can be added by calling this method multiple times with the same parameters.

Exceptions

ArgumentNullException

When request is null.
When content is null or Empty.
When fileName is null or Empty.

Bcc(SendEmailRequest, params EmailAddress[])

Adds provided recipients to the Bcc recipient collection of the request.

public static SendEmailRequest Bcc(this SendEmailRequest request, params EmailAddress[] recipients)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
recipients EmailAddress[]
One or more EmailAddress objects to add to the request's recipient collection.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Duplicates can be added by calling this method multiple times with the same recipients.

Exceptions

ArgumentNullException

When request or recipients is null.

Bcc(SendEmailRequest, string, string?)

Adds provided email and displayName tuple as recipient to the Bcc recipient collection of the request.

public static SendEmailRequest Bcc(this SendEmailRequest request, string email, string? displayName = null)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
email string

Recipient's email address.

Required. Must be valid email address.

displayName string
Optional recipient's display name.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Duplicates can be added by calling this method multiple times with the same recipients.

Exceptions

ArgumentNullException

When request is null.
When email is null or Empty.

Category(SendEmailRequest, string?)

Sets provided category to the request.

public static SendEmailRequest Category(this SendEmailRequest request, string? category)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
category string

Value to initialize request's Category property.

Should be less or equal to 255 characters.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

Value must remain null if TemplateId is used to create email from template.

Exceptions

ArgumentNullException

When request is null.

Cc(SendEmailRequest, params EmailAddress[])

Adds provided recipients to the Cc recipient collection of the request.

public static SendEmailRequest Cc(this SendEmailRequest request, params EmailAddress[] recipients)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
recipients EmailAddress[]
One or more EmailAddress objects to add to the request's recipient collection.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Duplicates can be added by calling this method multiple times with the same recipients.

Exceptions

ArgumentNullException

When request or recipients is null.

Cc(SendEmailRequest, string, string?)

Adds provided email and displayName tuple as recipient to the Cc recipient collection of the request.

public static SendEmailRequest Cc(this SendEmailRequest request, string email, string? displayName = null)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
email string

Recipient's email address.

Required. Must be valid email address.

displayName string
Optional recipient's display name.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Duplicates can be added by calling this method multiple times with the same recipients.

Exceptions

ArgumentNullException

When request is null.
When email is null or Empty.

CustomVariable(SendEmailRequest, params KeyValuePair<string, string>[])

Adds provided variables to the CustomVariables collection of the request.

public static SendEmailRequest CustomVariable(this SendEmailRequest request, params KeyValuePair<string, string>[] variables)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
variables KeyValuePair<string, string>[]

One or more key/value pairs to add to the request's CustomVariables collection.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Any existing variables with the same keys will be overridden.

Exceptions

ArgumentNullException

When request or variables is null.

CustomVariable(SendEmailRequest, string, string)

Adds provided custom variable to the Headers collection of the request.

public static SendEmailRequest CustomVariable(this SendEmailRequest request, string key, string value)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
key string

Variable key to add.

value string

Variable value to add.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Any existing variable with the same key will be overridden.

Exceptions

ArgumentNullException

When request is null.
When key is null or Empty.

From(SendEmailRequest, EmailAddress)

Sets provided sender to the request.

public static SendEmailRequest From(this SendEmailRequest request, EmailAddress sender)

Parameters

request SendEmailRequest

SendEmailRequest instance to update.

sender EmailAddress

EmailAddress object to initialize request's From property.

Returns

SendEmailRequest

Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

Exceptions

ArgumentNullException

When request or sender is null.

From(SendEmailRequest, string, string?)

Sets provided email and displayName as sender for the request.

public static SendEmailRequest From(this SendEmailRequest request, string email, string? displayName = null)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
email string

Sender's email address.

Required. Must be valid email address.

displayName string

Optional sender's display name.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

Exceptions

ArgumentNullException

When request is null.
When email is null or Empty.

Header(SendEmailRequest, params KeyValuePair<string, string>[])

Adds provided headers to the Headers collection of the request.

public static SendEmailRequest Header(this SendEmailRequest request, params KeyValuePair<string, string>[] headers)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
headers KeyValuePair<string, string>[]

One or more key/value pairs to add to the request's Headers collection.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Any existing headers with the same keys will be overridden.

Exceptions

ArgumentNullException

When request or headers is null.

Header(SendEmailRequest, string, string)

Adds provided header to the Headers collection of the request.

public static SendEmailRequest Header(this SendEmailRequest request, string key, string value)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
key string

Header key to add.

value string

Header value to add.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Any existing header with the same key will be overridden.

Exceptions

ArgumentNullException

When request is null.
When key is null or Empty.

Html(SendEmailRequest, string?)

Sets provided html to the request.

public static SendEmailRequest Html(this SendEmailRequest request, string? html)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
html string

Value to initialize request's HtmlBody property.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

It is a caller responsibility to ensure that html contains a valid, well-formed HTML markup and is sanitized properly.

Subsequent calls will override value that was set before (last wins).

Value must remain null if TemplateId is used to create email from template.

Exceptions

ArgumentNullException

When request is null.

ReplyTo(SendEmailRequest, EmailAddress?)

Sets provided replyTo address in the request.

public static SendEmailRequest ReplyTo(this SendEmailRequest request, EmailAddress? replyTo)

Parameters

request SendEmailRequest

SendEmailRequest instance to update.

replyTo EmailAddress

EmailAddress object to initialize request's ReplyTo property.

Returns

SendEmailRequest

Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

Exceptions

ArgumentNullException

When request is null.

ReplyTo(SendEmailRequest, string, string?)

Sets provided email and displayName as 'Reply To' address in the request.

public static SendEmailRequest ReplyTo(this SendEmailRequest request, string email, string? displayName = null)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
email string

'Reply To' email address.

Required. Must be valid email address.

displayName string

Optional 'Reply To' display name.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

Exceptions

ArgumentNullException

When request is null.
When email is null or Empty.

Subject(SendEmailRequest, string)

Sets provided subject to the request.

public static SendEmailRequest Subject(this SendEmailRequest request, string subject)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
subject string

Value to initialize request's Subject property.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

Value must remain null if TemplateId is used to create email from template.

Exceptions

ArgumentNullException

When request is null.
When subject is null or Empty.

Template(SendEmailRequest, string)

Sets provided templateId to the request.

public static SendEmailRequest Template(this SendEmailRequest request, string templateId)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
templateId string

Value containing UUID of the template to initialize request's TemplateId property.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

When TemplateId is set, then Subject, TextBody, HtmlBody and Category properties are forbidden and must be set to null.

Exceptions

ArgumentNullException

When request is null.
When templateId is null or Empty.

TemplateVariables(SendEmailRequest, object?)

Sets provided templateVariables to the request.

public static SendEmailRequest TemplateVariables(this SendEmailRequest request, object? templateVariables)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
templateVariables object

Value containing object to initialize request's TemplateVariables property.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

Will be used only in case template is set.

Exceptions

ArgumentNullException

When request is null.

Text(SendEmailRequest, string?)

Sets provided text to the request.

public static SendEmailRequest Text(this SendEmailRequest request, string? text)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
text string

Value to initialize request's TextBody property.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Subsequent calls will override value that was set before (last wins).

Value must remain null if TemplateId is used to create email from template.

Exceptions

ArgumentNullException

When request is null.

To(SendEmailRequest, params EmailAddress[])

Adds provided recipients to the To recipient collection of the request.

public static SendEmailRequest To(this SendEmailRequest request, params EmailAddress[] recipients)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
recipients EmailAddress[]

One or more EmailAddress objects to add to the request's recipient collection.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Duplicates can be added by calling this method multiple times with the same recipients.

Exceptions

ArgumentNullException

When request or recipients is null.

To(SendEmailRequest, string, string?)

Adds provided email and displayName tuple as recipient to the To recipient collection of the request.

public static SendEmailRequest To(this SendEmailRequest request, string email, string? displayName = null)

Parameters

request SendEmailRequest
SendEmailRequest instance to update.
email string

Recipient's email address.

Required. Must be valid email address.

displayName string

Optional recipient's display name.

Returns

SendEmailRequest
Updated SendEmailRequest instance so subsequent calls can be chained.

Remarks

Duplicates can be added by calling this method multiple times with the same recipients.

Exceptions

ArgumentNullException

When request is null.
When email is null or Empty.