Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need clarification on implementing custom SMTP response codes in IMailboxFilter #243

Open
c3328148 opened this issue Nov 27, 2024 · 1 comment

Comments

@c3328148
Copy link

I'm trying to implement custom SMTP response codes in my mailbox filters but finding some inconsistencies in the documentation and implementation.

In the sample code from the README:

public class SampleMailboxFilter : IMailboxFilter, IMailboxFilterFactory
{
    public Task<MailboxFilterResult> CanAcceptFromAsync(ISessionContext context, IMailbox @from, int size, CancellationToken cancellationToken)
    {
        if (String.Equals(@from.Host, "test.com"))
        {
            return Task.FromResult(MailboxFilterResult.Yes);
        }
        return Task.FromResult(MailboxFilterResult.NoPermanently);
    }
    // ...
}

However, when implementing this in SmtpServer 10.0.0.1:

MailboxFilterResult appears to be deprecated/removed
The base MailboxFilter class uses bool return types instead
It's unclear what the current best practice is for returning custom SMTP response codes

Currently, I'm setting the response through context.Response = SmtpResponse.Create(code, message), but I'm unsure if this is the recommended approach.
Could you please clarify:

What is the current recommended way to implement custom SMTP responses in mailbox filters?
Is there a preferred method between using context.Properties["SmtpResponse"] vs context.Response?
Could you provide an updated example showing the correct implementation for version 10.0.0.1?

Thanks for your help!
@cosullivan
Copy link
Owner

Hi,

If you want to return custom SMTP responses now, you can just throw an SmtpResponseException.

throw new SmtpResponseException(new SmtpResponse(SmtpReplyCode.MailboxUnavailable, "this is a custom error"));

The SmtpResponseException is handled internally.

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

No branches or pull requests

2 participants