{"id":28716250,"url":"https://github.com/modfin/smtpx","last_synced_at":"2025-06-15T02:39:44.250Z","repository":{"id":282891410,"uuid":"949995883","full_name":"modfin/smtpx","owner":"modfin","description":"A lightweight SMTP server package written in Go that feels familiar.","archived":false,"fork":false,"pushed_at":"2025-06-13T14:50:21.000Z","size":1049,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T15:23:48.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/modfin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"zenodo":null}},"created_at":"2025-03-17T13:19:20.000Z","updated_at":"2025-06-13T14:49:23.000Z","dependencies_parsed_at":"2025-06-05T14:32:49.230Z","dependency_job_id":"b3909378-1ee6-48eb-92a3-ec634b947a70","html_url":"https://github.com/modfin/smtpx","commit_stats":null,"previous_names":["modfin/smtpx"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/modfin/smtpx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fsmtpx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fsmtpx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fsmtpx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fsmtpx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modfin","download_url":"https://codeload.github.com/modfin/smtpx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fsmtpx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259914055,"owners_count":22931297,"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":[],"created_at":"2025-06-15T02:39:43.452Z","updated_at":"2025-06-15T02:39:44.238Z","avatar_url":"https://github.com/modfin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# SMTPX\n\n\u003e A lightweight SMTP server package written in Go that feels familiar.\n\n\n## Installation\n\n```bash\ngo get github.com/modfin/smtpx\n```\n\n## Usage\n\nOne idea for smtpx is to have it feel familiar and have the same feel as the standard library has for `net/http`.\n\n```go\n\npackage main\n\nimport (\n\t\"context\"\n\t\"crypto/tls\"\n\t\"fmt\"\n\t\"github.com/modfin/smtpx\"\n\t\"github.com/modfin/smtpx/envelope\"\n\t\"github.com/modfin/smtpx/middleware\"\n\t\"github.com/modfin/smtpx/responses\"\n\t\"golang.org/x/crypto/acme/autocert\"\n\t\"log/slog\"\n\t\"os\"\n\t\"os/signal\"\n\t\"time\"\n)\n\nfunc main() {\n\n\thostname := \"example.com\"\n\tcertManager := \u0026autocert.Manager{\n\t\tPrompt:     autocert.AcceptTOS,\n\t\tCache:      autocert.DirCache(\"acme-cache\"),\n\t\tHostPolicy: autocert.HostWhitelist(hostname),\n\t}\n\n\tslog.SetLogLoggerLevel(slog.LevelDebug)\n\n\tserver := smtpx.Server{\n\t\tLogger: slog.Default(),\n\n\t\t// Hostname is used for HELO command, and is required for TLS\n\t\tHostname: hostname,\n\t\tAddr:     \":25\",\n\n\t\t// TLSConfig is optional and is used for STARTTLS command\n\t\tTLSConfig: \u0026tls.Config{ // example using autocert for TLS\n\t\t\tGetCertificate: certManager.GetCertificate,\n\t\t},\n\n\t\t// Middlewares are executed in order\n\t\tMiddlewares: []smtpx.Middleware{\n\t\t\tmiddleware.Logger(slog.Default()),\n\t\t\tmiddleware.Recover,\n\t\t\tmiddleware.AddReturnPath,\n\t\t},\n\n\t\t// Handler for incoming emails\n\t\t// smtpx.NewHandler creates a handler from a function\n\t\tHandler: smtpx.NewHandler(func(e *envelope.Envelope) smtpx.Response {\n\n\t\t\tfmt.Println(\"Command MAIL\", e.MailFrom)\n\t\t\tfmt.Println(\"Command RCPT\", e.RcptTo)\n\t\t\tfmt.Println(\"Command DATA\", e.Data.String())\n\n\t\t\t// Opening the envelope and getting the mail\n\t\t\t// ie. Splitting the Data section of a email into header and body\n\t\t\tmail, err := e.Mail()\n\t\t\tif err != nil {\n\t\t\t\treturn responses.FailSyntaxError\n\t\t\t}\n\n\t\t\t// Parses headers while keeping encoding.\n\t\t\t// For human-readable decoded format, use mail.Headers()\n\t\t\theaders, err := mail.HeadersLiteral()\n\n\t\t\t// Error handling ignored for brevity\n\t\t\tfmt.Println(\"From:\", headers.From())\n\t\t\tfmt.Println(\"To:\", headers.To())\n\t\t\tfmt.Println(\"Subject:\", headers.Get(\"Subject\"))\n\t\t\tfmt.Println(\"Body:\", string(mail.Body()))\n\n\t\t\treturn smtpx.NewResponse(250, \"OK\")\n\t\t}),\n\t}\n\n\t// Graceful shutdown\n\tgo func() {\n\t\tsig := make(chan os.Signal, 1)\n\t\tsignal.Notify(sig, os.Interrupt, os.Kill)\n\t\t\u003c-sig\n\n\t\tctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n\t\tdefer cancel()\n\n\t\terr := server.Shutdown(ctx)\n\t\tif err != nil {\n\t\t\tslog.Default().Error(\"failed to shutdown server\", \"err\", err)\n\t\t}\n\t}()\n\n\tif err := server.ListenAndServe(); err != nil {\n\t\tslog.Default().Error(\"failed to start server\", \"err\", err)\n\t}\n}\n\n\n\n```\n\n\n## Tribute\n\n### A Fork\n`smtpx` started out as a fork of `go-guerrilla` but there is very little left from the original project.\nThe goal is quite different for `smtpx`, and pretty much everything has been rewritten in \na more go-like way focused on have `smtpx` work as a package and not a stand-alone server.   \n\nhttps://github.com/phires/go-guerrilla (original https://github.com/flashmob/go-guerrilla)\n\n### Other projects\n\nThere are a few other smtp servers written in go, so please have look before using `smtpx`.\n\n- https://github.com/emersion/go-smtp\n- https://github.com/phires/go-guerrilla\n- https://github.com/foxcpp/maddy\n\n\n### License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodfin%2Fsmtpx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodfin%2Fsmtpx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodfin%2Fsmtpx/lists"}