Skip to content

Models

The Core layer defines search filter models and the API layer defines DTOs (Data Transfer Objects) for REST responses. This page covers both.

EmailSearchFilters

EmailSearchFilters defines the parameters for searching emails within a user's inbox. All fields are nullable -- a null field means "don't filter on this criterion."

csharp
public class EmailSearchFilters
{
    public string? Query { get; set; }
    public DateTimeOffset? FromDate { get; set; }
    public DateTimeOffset? ToDate { get; set; }
    public bool? HasAttachments { get; set; }
    public bool? IsRead { get; set; }
}
FieldDescription
QueryFull-text search across From address, Subject, and Body fields. The implementation uses SQL ILIKE for case-insensitive matching.
FromDateInclude only emails received on or after this date.
ToDateInclude only emails received on or before this date.
HasAttachmentsWhen true, only emails with attachments. When false, only emails without.
IsReadWhen true, only read emails. When false, only unread.

These filters are used by both the EmailsController and ExternalEmailsController search endpoints, and are passed through to IEmailRepository.SearchByUserIdAsync.

API DTOs

The API project (Relate.Smtp.Api/Models/) defines DTOs that shape the REST API responses. These are separate from the Core entities to decouple the API contract from the database schema.

EmailListItemDto

A compact representation of an email for list views:

csharp
public record EmailListItemDto(
    Guid Id,
    string MessageId,
    string FromAddress,
    string? FromDisplayName,
    string Subject,
    DateTimeOffset ReceivedAt,
    long SizeBytes,
    bool IsRead,
    int AttachmentCount
);

EmailDetailDto

Full email details including body and recipient/attachment lists:

csharp
public record EmailDetailDto(
    Guid Id, string MessageId, string FromAddress, string? FromDisplayName,
    string Subject, string? TextBody, string? HtmlBody,
    DateTimeOffset ReceivedAt, long SizeBytes, bool IsRead,
    List<EmailRecipientDto> Recipients,
    List<EmailAttachmentDto> Attachments
);

EmailListResponse

Paginated list response with inbox statistics:

csharp
public record EmailListResponse(
    List<EmailListItemDto> Items,
    int TotalCount,
    int UnreadCount,
    int Page,
    int PageSize
);

LabelDto

Label data for the labels management UI. Defined in LabelDto.cs.

OutboundEmailDto

Outbound email data for the compose, drafts, outbox, and sent views. Defined in OutboundEmailDto.cs.

ProfileDto

User profile data including primary email and additional addresses. Defined in ProfileDto.cs.

PushSubscriptionDto

Push subscription data for managing notification subscriptions. Defined in PushSubscriptionDto.cs.

UserPreferenceDto

User preference data for the settings UI. Defined in UserPreferenceDto.cs.

SmtpApiKeyDto

API key metadata (never includes the raw key) for the credentials management UI:

csharp
public record SmtpApiKeyDto(
    Guid Id,
    string Name,
    DateTimeOffset CreatedAt,
    DateTimeOffset? LastUsedAt,
    bool IsActive,
    IReadOnlyList<string> Scopes
);

API Key Scopes

The ApiKeyScopes class defines the valid permission scopes:

ScopeDescription
smtpSMTP server authentication
pop3POP3 server authentication
imapIMAP server authentication
api:readREST API read access (external)
api:writeREST API write access (external)
appMobile/desktop app access

Mapping Extensions

EmailMappingExtensions provides ToListItemDto() and ToDetailDto() extension methods on the Email entity. These handle the mapping from domain entities to DTOs, including resolving per-user read status from the EmailRecipient records.

Released under the MIT License.