Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

227 Commits

Repository files navigation

What is SmtpServer?

NuGet

SmtpServer is a simple, but highly functional SMTP server implementation. Written entirely in C# it takes full advantage of the .NET TPL to achieve maximum performance.

SmtpServer is available via NuGet

What does it support?

SmtpServer currently supports the following ESMTP extensions:

  • STARTTLS
  • SIZE
  • PIPELINING
  • 8BITMIME
  • AUTH PLAIN LOGIN

How can it be used?

At its most basic, it only takes a few lines of code for the server to be listening to incoming requests.

varoptions=newSmtpServerOptionsBuilder().ServerName("localhost").Port(25,587).Build();varsmtpServer=newSmtpServer.SmtpServer(options);awaitsmtpServer.StartAsync(CancellationToken.None);

What hooks are provided?

There are three hooks that can be implemented; IMessageStore, IMailboxFilter, and IUserAuthenticator.

varoptions=newSmtpServerOptionsBuilder().ServerName("localhost").Port(25,587).Port(465,isSecure:true).Certificate(CreateX509Certificate2()).MessageStore(newSampleMessageStore()).MailboxFilter(newSampleMailboxFilter()).UserAuthenticator(newSampleUserAuthenticator()).Build();varsmtpServer=newSmtpServer.SmtpServer(options);awaitsmtpServer.StartAsync(CancellationToken.None);
publicclassSampleMessageStore:MessageStore{publicoverrideTask<SmtpResponse>SaveAsync(ISessionContextcontext,IMessageTransactiontransaction,CancellationTokencancellationToken){vartextMessage=(ITextMessage)transaction.Message;varmessage=MimeKit.MimeMessage.Load(textMessage.Content);Console.WriteLine(message.TextBody);returnTask.FromResult(SmtpResponse.Ok);}}
publicclassSampleMailboxFilter:IMailboxFilter,IMailboxFilterFactory{publicTask<MailboxFilterResult>CanAcceptFromAsync(ISessionContextcontext,IMailbox@from,intsize,CancellationTokencancellationToken){if(String.Equals(@from.Host,"test.com")){returnTask.FromResult(MailboxFilterResult.Yes);}returnTask.FromResult(MailboxFilterResult.NoPermanently);}publicTask<MailboxFilterResult>CanDeliverToAsync(ISessionContextcontext,IMailboxto,IMailbox@from,CancellationTokentoken){returnTask.FromResult(MailboxFilterResult.Yes);}publicIMailboxFilterCreateInstance(ISessionContextcontext){returnnewSampleMailboxFilter();}}
publicclassSampleUserAuthenticator:IUserAuthenticator,IUserAuthenticatorFactory{publicTask<bool>AuthenticateAsync(ISessionContextcontext,stringuser,stringpassword,CancellationTokentoken){Console.WriteLine("User={0} Password={1}",user,password);returnTask.FromResult(user.Length>4);}publicIUserAuthenticatorCreateInstance(ISessionContextcontext){returnnewSampleUserAuthenticator();}}

About

A SMTP Server component written in C#

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages