Class EmailRequestBuilder
A set of helper methods to streamline EmailRequest instance construction using fluent style.
public static class EmailRequestBuilder
- Inheritance
-
EmailRequestBuilder
Methods
Attach<T>(T, params Attachment[])
Adds provided attachments to the Attachments
collection of the request.
public static T Attach<T>(this T request, params Attachment[] attachments) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
attachmentsAttachment[]One or more Attachment objects to add to the request's Attachments collection.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Duplicates can be added by calling this method multiple times with the same Attachment object.
Exceptions
- ArgumentNullException
When
requestorattachmentsis null.
Attach<T>(T, string, string, DispositionType?, string?, string?)
Adds provided attachment to the Attachments
collection of the request.
public static T Attach<T>(this T request, string content, string fileName, DispositionType? disposition = null, string? mimeType = null, string? contentId = null) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
contentstring-
The Base64 encoded content of the attachment.
Required. Must be non-empty string.
fileNamestring-
Attachment file name.
Required. Must be non-empty string.
dispositionDispositionType-
The attachment's content disposition, specifying how you would like the attachment to be displayed.
Optional. Defaults to Attachment if not specified explicitly.
mimeTypestring-
Attachment MIME type identifier (e.g. "text/plain", "application/pdf", etc.)
Optional.
contentIdstring-
The attachment's content ID.
Optional.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Duplicates can be added by calling this method multiple times with the same parameters.
Exceptions
- ArgumentNullException
When
requestis null.
Whencontentis null or Empty.
WhenfileNameis null or Empty.
Category<T>(T, string?)
Sets provided category to the request.
public static T Category<T>(this T request, string? category) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
categorystringValue to initialize request's Category property.
Should be less or equal to 255 characters.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
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
requestis null.
CustomVariable<T>(T, params KeyValuePair<string, string>[])
Adds provided variables to the CustomVariables
collection of the request.
public static T CustomVariable<T>(this T request, params KeyValuePair<string, string>[] variables) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
variablesKeyValuePair<string, string>[]One or more key/value pairs to add to the request's CustomVariables collection.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Any existing variables with the same keys will be overridden.
Exceptions
- ArgumentNullException
When
requestorvariablesis null.
CustomVariable<T>(T, string, string)
Adds provided custom variable to the CustomVariables
collection of the request.
public static T CustomVariable<T>(this T request, string key, string value) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
keystringVariable key to add.
valuestringVariable value to add.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Any existing variable with the same key will be overridden.
Exceptions
From<T>(T, EmailAddress)
Sets provided sender to the request.
public static T From<T>(this T request, EmailAddress sender) where T : EmailRequest
Parameters
requestTEmailRequest instance to update.
senderEmailAddressEmailAddress object to initialize request's From property.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Subsequent calls will override value that was set before (last wins).
Exceptions
- ArgumentNullException
When
requestorsenderis null.
From<T>(T, string, string?)
Sets provided email and displayName as sender
for the request.
public static T From<T>(this T request, string email, string? displayName = null) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
emailstringSender's email address.
Required. Must be valid email address.
displayNamestringOptional sender's display name.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Exceptions
Header<T>(T, params KeyValuePair<string, string>[])
Adds provided headers to the Headers
collection of the request.
public static T Header<T>(this T request, params KeyValuePair<string, string>[] headers) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
headersKeyValuePair<string, string>[]One or more key/value pairs to add to the request's Headers collection.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Any existing headers with the same keys will be overridden.
Exceptions
- ArgumentNullException
When
requestorheadersis null.
Header<T>(T, string, string)
Adds provided header to the Headers
collection of the request.
public static T Header<T>(this T request, string key, string value) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
keystringHeader key to add.
valuestringHeader value to add.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Any existing header with the same key will be overridden.
Exceptions
Html<T>(T, string?)
Sets provided html to the request.
public static T Html<T>(this T request, string? html) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
htmlstringValue to initialize request's HtmlBody property.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
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
requestis null.
ReplyTo<T>(T, EmailAddress?)
Sets provided replyTo address in the request.
public static T ReplyTo<T>(this T request, EmailAddress? replyTo) where T : EmailRequest
Parameters
requestTEmailRequest instance to update.
replyToEmailAddressEmailAddress object to initialize request's ReplyTo property.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Subsequent calls will override value that was set before (last wins).
Exceptions
- ArgumentNullException
When
requestis null.
ReplyTo<T>(T, string, string?)
Sets provided email and displayName as 'Reply To' address
in the request.
public static T ReplyTo<T>(this T request, string email, string? displayName = null) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
emailstring'Reply To' email address.
Required. Must be valid email address.
displayNamestringOptional 'Reply To' display name.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Exceptions
Subject<T>(T, string)
Sets provided subject to the request.
public static T Subject<T>(this T request, string subject) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
subjectstringValue to initialize request's Subject property.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
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
TemplateVariables<T>(T, object?)
Sets provided templateVariables to the request.
public static T TemplateVariables<T>(this T request, object? templateVariables) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
templateVariablesobjectValue containing object to initialize request's TemplateVariables property.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
Remarks
Subsequent calls will override value that was set before (last wins).
Will be used only in case template is set.
Exceptions
- ArgumentNullException
When
requestis null.
Template<T>(T, string)
Sets provided templateId to the request.
public static T Template<T>(this T request, string templateId) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
templateIdstringValue containing UUID of the template to initialize request's TemplateId property.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
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
Text<T>(T, string?)
Sets provided text to the request.
public static T Text<T>(this T request, string? text) where T : EmailRequest
Parameters
requestT- EmailRequest instance to update.
textstringValue to initialize request's TextBody property.
Returns
- T
Updated EmailRequest instance so subsequent calls can be chained.
Type Parameters
T
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
requestis null.