Table of Contents

Class SendEmailRequest

Namespace
Mailtrap.Emails.Requests
Assembly
Mailtrap.Abstractions.dll

Represents request object used to send email.

public sealed record SendEmailRequest : IValidatable, IEquatable<SendEmailRequest>
Inheritance
SendEmailRequest
Implements

Properties

Attachments

Gets a collection of Attachment objects, where you can specify any attachments you want to include.

[JsonPropertyName("attachments")]
[JsonPropertyOrder(50)]
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
public IList<Attachment> Attachments { get; }

Property Value

IList<Attachment>

A collection of Attachment objects.

Bcc

Gets a collection of EmailAddress objects, defining who will receive a blind carbon copy of email.

[JsonPropertyName("bcc")]
[JsonPropertyOrder(40)]
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
public IList<EmailAddress> Bcc { get; }

Property Value

IList<EmailAddress>

A collection of EmailAddress objects.

Remarks

Must not contain more than 1000 recipients.
Each object in this collection must contain the recipient's email address.
Each object in this collection may optionally contain the recipient's name.
At least one recipient must be specified in one of the collections: To, Cc or Bcc.

Category

Gets or sets the category of email.

[JsonPropertyName("category")]
[JsonPropertyOrder(110)]
public string? Category { get; set; }

Property Value

string

Contains the category of the email.

Remarks

Should be null if TemplateId is set.
Otherwise must be less or equal to 255 characters.

Cc

Gets a collection of EmailAddress objects, defining who will receive a carbon copy of email.

[JsonPropertyName("cc")]
[JsonPropertyOrder(30)]
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
public IList<EmailAddress> Cc { get; }

Property Value

IList<EmailAddress>

A collection of EmailAddress objects.

Remarks

Must not contain more than 1000 recipients.
Each object in this collection must contain the recipient's email address.
Each object in this collection may optionally contain the recipient's name.
At least one recipient must be specified in one of the collections: To, Cc or Bcc.

CustomVariables

Gets a dictionary of values that are specific to the entire send that will be carried along with the email and its activity data.

[JsonPropertyName("custom_variables")]
[JsonPropertyOrder(70)]
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
public IDictionary<string, string> CustomVariables { get; }

Property Value

IDictionary<string, string>

A dictionary of variable keys and values.

Remarks

The key/value pairs must be strings.
Total size of custom variables in JSON form must not exceed 1000 bytes.

From

Gets or sets EmailAddress instance representing email's sender.

Required.

[JsonPropertyName("from")]
[JsonPropertyOrder(10)]
public EmailAddress? From { get; set; }

Property Value

EmailAddress

Instance, representing email's sender address and name.

Headers

Gets a dictionary of header names and values to substitute for them.

[JsonPropertyName("headers")]
[JsonPropertyOrder(60)]
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
public IDictionary<string, string> Headers { get; }

Property Value

IDictionary<string, string>

A dictionary of header names and values.

Remarks

The key/value pairs must be strings.
You must ensure these are properly encoded if they contain unicode characters.
These headers cannot be one of the reserved headers.
"Content-Transfer-Encoding" header will be ignored and replaced with "quoted-printable".

HtmlBody

Gets or sets HTML version of the body of the email.

[JsonPropertyName("html")]
[JsonPropertyOrder(100)]
public string? HtmlBody { get; set; }

Property Value

string

Contains the HTML body of the email.

Remarks

Must be null if TemplateId is set.
Required in the absence of TemplateId and TextBody.

ReplyTo

Gets or sets EmailAddress representing 'Reply To' email field.

[JsonPropertyName("reply_to")]
[JsonPropertyOrder(15)]
public EmailAddress? ReplyTo { get; set; }

Property Value

EmailAddress

Representing 'Reply To' address and name.

Subject

Gets or sets the global or 'message level' subject of email.
This may be overridden by subject lines set in personalizations.

[JsonPropertyName("subject")]
[JsonPropertyOrder(80)]
public string? Subject { get; set; }

Property Value

string

Contains the subject of the email.

Remarks

Must be null if TemplateId is set.

Required in case HtmlBody and(or) TextBody is used.
Should be non-empty string in this case.

TemplateId

Gets or sets UUID of email template.

[JsonPropertyName("template_uuid")]
[JsonPropertyOrder(120)]
public string? TemplateId { get; set; }

Property Value

string

Contains the UUID of email template.

Remarks

If provided, then Subject, Category, TextBody and HtmlBody properties are forbidden and must be null.
Email subject, text and html will be generated from template using optional TemplateVariables.

TemplateVariables

Gets or sets optional template variables that will be used to generate actual subject, text and html from email template.

[JsonPropertyName("template_variables")]
[JsonPropertyOrder(130)]
public object? TemplateVariables { get; set; }

Property Value

object

Contains template variables object.

Remarks

Will be used only in case TemplateId is set.

TextBody

Gets or sets the text version of the body of the email.

[JsonPropertyName("text")]
[JsonPropertyOrder(90)]
public string? TextBody { get; set; }

Property Value

string

Contains the text body of the email.

Remarks

Must be null if TemplateId is set.
Otherwise, can be used along with HtmlBody to create a fall-back for non-html clients.
Required in the absence of TemplateId and HtmlBody.

To

Gets a collection of EmailAddress objects, defining who will receive a copy of email.

[JsonPropertyName("to")]
[JsonPropertyOrder(20)]
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
public IList<EmailAddress> To { get; }

Property Value

IList<EmailAddress>

A collection of EmailAddress objects.

Remarks

Must not contain more than 1000 recipients.
Each object in this collection must contain the recipient's email address.
Each object in this collection may optionally contain the recipient's name.
At least one recipient must be specified in one of the collections: To, Cc or Bcc.

Methods

Create()

Factory method that creates a new instance of SendEmailRequest request.

public static SendEmailRequest Create()

Returns

SendEmailRequest

New SendEmailRequest instance.

Validate()

Validates the current instance.

public ValidationResult Validate()

Returns

ValidationResult

Object containing validation errors, if any.