Table of Contents

Class SmtpSender

Namespace
FishMMO.ControlPanel.Services
Assembly
FishMMO-ControlPanel.dll

The panel's SMTP sender, configured exactly the way the LoginServer's is.

public sealed class SmtpSender : ISmtpSender
Inheritance
SmtpSender
Implements
Inherited Members

Remarks

Configuration is deliberately identical to FishMMO.Server.Implementation.Smtp.SmtpService. The same environment variables (FISHMMO_SMTP_HOST and friends) take precedence over the same configuration keys (Smtp:Host and friends), so one set of credentials configures whichever process happens to be draining the queue. Two processes that had to be configured differently to send the same mail would be a trap waiting for whoever migrates the drain again.

System.Net.Mail, and no new package. SmtpClient is formally obsolete for new work and MailKit is the better library — it speaks modern authentication, reuses connections, and is what Microsoft's own obsoletion notice points at. Taking a dependency is not a decision this change is allowed to make, so this uses the framework client, the same one the LoginServer already used against the same relay. If the relay ever needs OAuth or connection reuse, that is the moment to revisit it.

EnableSsl means STARTTLS, not implicit TLS. The client connects in the clear and upgrades, which is what port 587 expects and what the intended relay wants. Implicit TLS on port 465 is not supported by this client at all — pointing it at 465 hangs until the timeout rather than failing usefully — so a deployment that only offers 465 needs MailKit, not a configuration change.

Every message goes out as multipart/alternative: plain text and HTML. The previous sender set IsBodyHtml = true for everything, and three of the four bodies this system sends are plain text written with \n line breaks. Delivered as HTML those newlines collapse, and the result is one run-on paragraph with the code buried in the middle of a sentence — including a 43-character password reset token, which is exactly the kind of thing a reader has to be able to pick out and copy. Sending both parts also scores better with spam filters than either part alone.

The missing part is derived here rather than stored. The queue carries one body column and gains no second one: the LoginServer's own verification mail is already HTML and cannot be changed from this side, so the sender has to handle an HTML body correctly regardless — and once it does, deriving in the other direction costs nothing and fixes every message already sitting in the queue. See FishMMO.ControlPanel.Services.EmailBodyParts for how each direction is decided, and for why an already-HTML body is never escaped or wrapped twice.

Nothing here logs a body. A verification body carries the six-digit code and a reset body carries the token; both are credentials, and a log file is not a mailbox. The recipient, the subject and the outcome are logged, and that is all.

Constructors

SmtpSender(IConfiguration, ILogger<SmtpSender>)

Reads the SMTP settings once, at construction.

public SmtpSender(IConfiguration configuration, ILogger<SmtpSender> log)

Parameters

configuration IConfiguration
log ILogger<SmtpSender>

Remarks

Once, because a relay that changes underneath a running process is not a thing operators do and a half-applied credential change is worse than a restart.

Properties

ConfigurationSummary

One line naming where mail goes, or why it goes nowhere. Safe to log: it never contains the username or the password.

public string ConfigurationSummary { get; }

Property Value

string

Remarks

Built once, at construction, and never contains the credentials — so the drain can log it verbatim on the way up, whether it says where mail goes or why it does not go.

IsConfigured

Whether this deployment has a relay worth talking to.

public bool IsConfigured { get; }

Property Value

bool

Remarks

False is a supported state, not a fault. A panel brought up for development, or one standing in front of a shard whose mail goes out elsewhere, has no relay and should not be spending a database round trip every couple of seconds claiming messages it cannot deliver.

Methods

SendAsync(string, string, string, CancellationToken)

Sends one message, returning whether the relay accepted it.

public Task<bool> SendAsync(string to, string subject, string body, CancellationToken cancellationToken = default)

Parameters

to string

Recipient address.

subject string

Subject line.

body string

The stored body, either plain text or HTML. Both parts are derived from it; see SmtpSender.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<bool>

True when the relay accepted the message; false for every failure, which is what the queue records as an attempt.