{"id":13412700,"url":"https://github.com/mailhog/smtp","last_synced_at":"2025-10-29T20:41:30.620Z","repository":{"id":25034350,"uuid":"28453997","full_name":"mailhog/smtp","owner":"mailhog","description":"MailHog SMTP Protocol","archived":false,"fork":false,"pushed_at":"2021-10-20T15:16:17.000Z","size":102,"stargazers_count":75,"open_issues_count":7,"forks_count":33,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-20T03:06:19.741Z","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/mailhog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-24T16:13:49.000Z","updated_at":"2024-12-12T06:26:12.000Z","dependencies_parsed_at":"2022-07-16T00:00:39.581Z","dependency_job_id":null,"html_url":"https://github.com/mailhog/smtp","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/mailhog/smtp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailhog%2Fsmtp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailhog%2Fsmtp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailhog%2Fsmtp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailhog%2Fsmtp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mailhog","download_url":"https://codeload.github.com/mailhog/smtp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailhog%2Fsmtp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262915544,"owners_count":23383847,"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":"2024-07-30T20:01:28.027Z","updated_at":"2025-10-29T20:41:25.575Z","avatar_url":"https://github.com/mailhog.png","language":"Go","readme":"MailHog SMTP Protocol [![GoDoc](https://godoc.org/github.com/mailhog/smtp?status.svg)](https://godoc.org/github.com/mailhog/smtp) [![Build Status](https://travis-ci.org/mailhog/smtp.svg?branch=master)](https://travis-ci.org/mailhog/smtp)\n=========\n\n`github.com/mailhog/smtp` implements an SMTP server state machine.\n\nIt attempts to encapsulate as much of the SMTP protocol (plus its extensions) as possible\nwithout compromising configurability or requiring specific backend implementations.\n\n  * ESMTP server implementing [RFC5321](http://tools.ietf.org/html/rfc5321)\n  * Support for:\n    * AUTH [RFC4954](http://tools.ietf.org/html/rfc4954)\n    * PIPELINING [RFC2920](http://tools.ietf.org/html/rfc2920)\n    * STARTTLS [RFC3207](http://tools.ietf.org/html/rfc3207)\n\n```go\nproto := NewProtocol()\nreply := proto.Start()\nreply = proto.ProcessCommand(\"EHLO localhost\")\n// ...\n```\n\nSee [MailHog-Server](https://github.com/mailhog/MailHog-Server) and [MailHog-MTA](https://github.com/mailhog/MailHog-MTA) for example implementations.\n\n### Commands and replies\n\nInteraction with the state machine is via:\n* the `Parse` function\n* the `ProcessCommand` and `ProcessData` functions\n\nYou can mix the use of all three functions as necessary.\n\n#### Parse\n\n`Parse` should be used on a raw text stream. It looks for an end of line (`\\r\\n`), and if found, processes a single command. Any unprocessed data is returned.\n\nIf any unprocessed data is returned, `Parse` should be\ncalled again to process then next command.\n\n```go\ntext := \"EHLO localhost\\r\\nMAIL FROM:\u003ctest\u003e\\r\\nDATA\\r\\nTest\\r\\n.\\r\\n\"\n\nvar reply *smtp.Reply\nfor {\n  text, reply = proto.Parse(text)\n  if len(text) == 0 {\n    break\n  }\n}\n```\n\n#### ProcessCommand and ProcessData\n\n`ProcessCommand` should be used for an already parsed command (i.e., a complete\nSMTP \"line\" excluding the line ending).\n\n`ProcessData` should be used if the protocol is in `DATA` state.\n\n```go\nreply = proto.ProcessCommand(\"EHLO localhost\")\nreply = proto.ProcessCommand(\"MAIL FROM:\u003ctest\u003e\")\nreply = proto.ProcessCommand(\"DATA\")\nreply = proto.ProcessData(\"Test\\r\\n.\\r\\n\")\n```\n\n### Hooks\n\nThe state machine provides hooks to manipulate its behaviour.\n\nSee [![GoDoc](https://godoc.org/github.com/mailhog/smtp?status.svg)](https://godoc.org/github.com/mailhog/smtp) for more information.\n\n| Hook                               | Description\n| ---------------------------------- | -----------\n| LogHandler                         | Called for every log message\n| MessageReceivedHandler             | Called for each message received\n| ValidateSenderHandler              | Called after MAIL FROM\n| ValidateRecipientHandler           | Called after RCPT TO\n| ValidateAuthenticationHandler      | Called after AUTH\n| SMTPVerbFilter                     | Called for every SMTP command processed\n| TLSHandler                         | Callback mashup called after STARTTLS\n| GetAuthenticationMechanismsHandler | Called for each EHLO command\n\n### Behaviour flags\n\nThe state machine also exports variables to control its behaviour:\n\nSee [![GoDoc](https://godoc.org/github.com/mailhog/smtp?status.svg)](https://godoc.org/github.com/mailhog/smtp) for more information.\n\n| Variable               | Description\n| ---------------------- | -----------\n| RejectBrokenRCPTSyntax | Reject non-conforming RCPT syntax\n| RejectBrokenMAILSyntax | Reject non-conforming MAIL syntax\n| RequireTLS             | Require STARTTLS before other commands\n| MaximumRecipients      | Maximum recipients per message\n| MaximumLineLength      | Maximum length of SMTP line\n\n### Licence\n\nCopyright ©‎ 2014-2015, Ian Kent (http://iankent.uk)\n\nReleased under MIT license, see [LICENSE](LICENSE.md) for details.\n","funding_links":[],"categories":["邮件库","Email","電子郵件","电子邮件","\u003cspan id=\"电子邮件-email\"\u003e电子邮件 Email\u003c/span\u003e","邮件库`邮件管理和发送的go语言库`","Relational Databases","邮件"],"sub_categories":["SQL 查询语句构建库","Search and Analytic Databases","Advanced Console UIs","高級控制台界面","检索及分析资料库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailhog%2Fsmtp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmailhog%2Fsmtp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailhog%2Fsmtp/lists"}