{"id":13430955,"url":"https://github.com/cosullivan/SmtpServer","last_synced_at":"2025-03-16T06:31:48.076Z","repository":{"id":37580364,"uuid":"49756928","full_name":"cosullivan/SmtpServer","owner":"cosullivan","description":"A SMTP Server component written in C#","archived":false,"fork":false,"pushed_at":"2024-10-03T10:19:19.000Z","size":5798,"stargazers_count":694,"open_issues_count":23,"forks_count":163,"subscribers_count":63,"default_branch":"master","last_synced_at":"2024-10-08T12:29:41.777Z","etag":null,"topics":["dotnet","smtp","smtp-server"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cosullivan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["cosullivan"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2016-01-16T03:05:39.000Z","updated_at":"2024-10-07T15:49:29.000Z","dependencies_parsed_at":"2023-12-22T08:29:22.386Z","dependency_job_id":"aedb556a-ab78-4201-870c-db1cea0733f3","html_url":"https://github.com/cosullivan/SmtpServer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosullivan%2FSmtpServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosullivan%2FSmtpServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosullivan%2FSmtpServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosullivan%2FSmtpServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cosullivan","download_url":"https://codeload.github.com/cosullivan/SmtpServer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221656498,"owners_count":16858783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","smtp","smtp-server"],"created_at":"2024-07-31T02:00:59.280Z","updated_at":"2024-10-27T09:31:15.711Z","avatar_url":"https://github.com/cosullivan.png","language":"C#","readme":"# What is SmtpServer?\n\n[![NuGet](https://img.shields.io/nuget/v/SmtpServer.svg)](https://www.nuget.org/packages/SmtpServer/)\n\nSmtpServer 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.\n\nSmtpServer is available via [NuGet](https://www.nuget.org/packages/SmtpServer/)\n\n# Whats New?\n\nSee [here](https://github.com/cosullivan/SmtpServer/blob/master/Version8.md) for whats new in Version 8.\n\n# What does it support?\n\nSmtpServer currently supports the following ESMTP extensions:\n\n- STARTTLS\n- SIZE\n- PIPELINING\n- 8BITMIME\n- AUTH PLAIN LOGIN\n\n# How can it be used?\n\nAt its most basic, it only takes a few lines of code for the server to be listening to incoming requests.\n\n```cs\nvar options = new SmtpServerOptionsBuilder()\n    .ServerName(\"localhost\")\n    .Port(25, 587)\n    .Build();\n\nvar smtpServer = new SmtpServer.SmtpServer(options, ServiceProvider.Default);\nawait smtpServer.StartAsync(CancellationToken.None);\n```\n\n# What hooks are provided?\n\nThere are three hooks that can be implemented; IMessageStore, IMailboxFilter, and IUserAuthenticator.\n\n```cs\nvar options = new SmtpServerOptionsBuilder()\n    .ServerName(\"localhost\")\n    .Endpoint(builder =\u003e\n        builder\n            .Port(9025, true)\n            .AllowUnsecureAuthentication(false)\n            .Certificate(CreateCertificate()))\n    .Build();\n\nvar serviceProvider = new ServiceProvider();\nserviceProvider.Add(new SampleMessageStore());\nserviceProvider.Add(new SampleMailboxFilter());\nserviceProvider.Add(new SampleUserAuthenticator());\n\nvar smtpServer = new SmtpServer.SmtpServer(options, serviceProvider);\nawait smtpServer.StartAsync(CancellationToken.None);\n\n// to create an X509Certificate for testing you need to run MAKECERT.EXE and then PVK2PFX.EXE\n// http://www.digitallycreated.net/Blog/38/using-makecert-to-create-certificates-for-development\nstatic X509Certificate2 CreateCertificate()\n{\n    var certificate = File.ReadAllBytes(@\"Certificate.pfx\");\n\n    return new X509Certificate2(certificate, \"P@ssw0rd\");\n}\n```\n\n```cs\npublic class SampleMessageStore : MessageStore\n{\n    public override async Task\u003cSmtpResponse\u003e SaveAsync(ISessionContext context, IMessageTransaction transaction, ReadOnlySequence\u003cbyte\u003e buffer, CancellationToken cancellationToken)\n        {\n            await using var stream = new MemoryStream();\n\n            var position = buffer.GetPosition(0);\n            while (buffer.TryGet(ref position, out var memory))\n            {\n                await stream.WriteAsync(memory, cancellationToken);\n            }\n\n            stream.Position = 0;\n\n            var message = await MimeKit.MimeMessage.LoadAsync(stream, cancellationToken);\n            Console.WriteLine(message.TextBody);\n\n            return SmtpResponse.Ok;\n        }\n}\n```\n\n```cs\npublic class SampleMailboxFilter : IMailboxFilter, IMailboxFilterFactory\n{\n    public Task\u003cMailboxFilterResult\u003e CanAcceptFromAsync(ISessionContext context, IMailbox @from, int size, CancellationToken cancellationToken)\n    {\n        if (String.Equals(@from.Host, \"test.com\"))\n        {\n            return Task.FromResult(MailboxFilterResult.Yes);\n        }\n\n        return Task.FromResult(MailboxFilterResult.NoPermanently);\n    }\n\n    public Task\u003cMailboxFilterResult\u003e CanDeliverToAsync(ISessionContext context, IMailbox to, IMailbox @from, CancellationToken token)\n    {\n        return Task.FromResult(MailboxFilterResult.Yes);\n    }\n\n    public IMailboxFilter CreateInstance(ISessionContext context)\n    {\n\treturn new SampleMailboxFilter();\n    }\n}\n```\n\n```cs\npublic class SampleUserAuthenticator : IUserAuthenticator, IUserAuthenticatorFactory\n{\n    public Task\u003cbool\u003e AuthenticateAsync(ISessionContext context, string user, string password, CancellationToken token)\n    {\n        Console.WriteLine(\"User={0} Password={1}\", user, password);\n\n        return Task.FromResult(user.Length \u003e 4);\n    }\n\n    public IUserAuthenticator CreateInstance(ISessionContext context)\n    {\n\treturn new SampleUserAuthenticator();\n    }\n}\n```\n","funding_links":["https://github.com/sponsors/cosullivan"],"categories":["Frameworks, Libraries and Tools","框架, 库和工具","Mail"],"sub_categories":["Mail","邮件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosullivan%2FSmtpServer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosullivan%2FSmtpServer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosullivan%2FSmtpServer/lists"}