Interface IEmailQueueService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
Service for the outbound email queue. Emails are enqueued by the application and delivered asynchronously by a background SMTP processor.
public interface IEmailQueueService
Methods
DequeueNextAsync(string, CancellationToken)
Atomically claims and dequeues the next pending email using
FOR UPDATE SKIP LOCKED. Safe for concurrent LoginServers.
Throws DatabaseEntityNotFoundException if the queue is empty.
Task<DatabaseResult<EmailQueueData>> DequeueNextAsync(string claimedBy, CancellationToken cancellationToken = default)
Parameters
claimedBystringIdentifier of the claiming server (e.g. server name).
cancellationTokenCancellationTokenCancellation token.
Returns
EnqueueAsync(string, string, string, string, EmailKind, CancellationToken)
Enqueues an email for asynchronous delivery.
Task<DatabaseResult> EnqueueAsync(string recipientEmail, string recipientUsername, string subject, string body, EmailKind kind = EmailKind.Verification, CancellationToken cancellationToken = default)
Parameters
recipientEmailstringRecipient email address.
recipientUsernamestringAssociated account username.
subjectstringEmail subject line.
bodystringEmail body (plain-text or HTML).
kindEmailKindWhat the mail is for. Defaults to Verification, which is both the column default and the meaning every row had before kinds existed, so a caller that does not care keeps the behaviour it always had. A password reset MUST pass PasswordReset: the drain stamps
verification_email_sent_atafter delivering a verification mail, and stamping it for a reset would end an unverified account's grace period — locking the player out of the game and the panel at the moment they recovered their password.cancellationTokenCancellationTokenCancellation token.
Returns
HasPendingForUserAsync(string, EmailKind?, CancellationToken)
Returns true if the specified user already has an unsent email of
kind in the queue. Prevents duplicate mail piling up.
Task<DatabaseResult<bool>> HasPendingForUserAsync(string recipientUsername, EmailKind? kind = null, CancellationToken cancellationToken = default)
Parameters
recipientUsernamestringkindEmailKind?cancellationTokenCancellationToken
Returns
Remarks
Pass the kind you are about to send. The queue carries more than one kind, so a blind check answers a different question than the caller asked: a pending password reset would suppress the verification mail an unverified player is waiting for. Null means any kind, and is almost never what a caller wants.
MarkFailedAsync(long, string, int, CancellationToken)
Marks an email delivery attempt as failed and increments the attempt counter.
Task<DatabaseResult> MarkFailedAsync(long id, string error, int maxAttempts = 5, CancellationToken cancellationToken = default)
Parameters
idlongerrorstringmaxAttemptsintcancellationTokenCancellationToken
Returns
Remarks
While attempts remain the claim is released, which is what puts the message back in
line for another login server to pick up. Once maxAttempts is
reached the claim is kept, which takes the message out of circulation and leaves it
in the queue with its error for an operator to investigate or retry by hand.
MarkSentAsync(long, CancellationToken)
Marks an email as successfully sent.
Task<DatabaseResult> MarkSentAsync(long id, CancellationToken cancellationToken = default)
Parameters
idlongcancellationTokenCancellationToken