Skip to content

Conversation

@tinohager
Copy link
Contributor

Introduces a CustomGreetingMessage property to ISmtpServerOptions and SmtpServerOptionsBuilder, allowing configuration of the initial SMTP greeting sent to clients. SmtpSession now uses this custom message if set, otherwise defaults to the standard greeting with server name and version.

Fix issue

An example of the server configuration

var options = new SmtpServerOptionsBuilder()
    .ServerName("SMTP Server")
    .Port(9025)
    .CustomGreetingMessage("Hi")
    .Build();

220 SMTP Server Hi

Introduces a CustomGreetingMessage property to ISmtpServerOptions and SmtpServerOptionsBuilder, allowing configuration of the initial SMTP greeting sent to clients. SmtpSession now uses this custom message if set, otherwise defaults to the standard greeting with server name and version.
/// This message is returned after the client connects and before any commands are issued (e.g., "220 mail.example.com v1.0 ESMTP ready").
/// If not set, a default greeting will be used.
/// </summary>
public string CustomGreetingMessage { get; set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should actually be something like

Func<ISmtpContext, string> CustomGreetingMessage

which would give the ability to make the message dynamic?

@tinohager
Copy link
Contributor Author

tinohager commented Jul 27, 2025 via email

@cosullivan
Copy link
Owner

I've already thought about it. I think the only variable that is interesting is the version number but this is not in the SmtpContext.

I think its worth changing this to a function as people might want to rotate greeing messages or customize it somehow... even if what they need isnt in the context, they will still have customization if this is a function.

@tinohager
Copy link
Contributor Author

tinohager commented Aug 3, 2025

An example of the server configuration

var options = new SmtpServerOptionsBuilder()
    .ServerName("SMTP Server")
    .Port(9025)
    .CustomGreetingMessage(MyCustomGreeting)
    .Build();

private static string MyCustomGreeting(ISessionContext context)
{
    return $"220 {context.ServerOptions.ServerName} hello";
}

220 SMTP Server Hi

@tinohager
Copy link
Contributor Author

@cosullivan Is this what you had in mind?

It would now also be possible to return the following in the greeting during maintenance

554 Service unavailable

@cosullivan cosullivan merged commit 2e280a4 into cosullivan:master Aug 3, 2025
1 check passed
@tinohager tinohager deleted the feature/custom-greeting-message branch August 4, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants