Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

MailHog SMTP Protocol

License

NotificationsYou must be signed in to change notification settings

mailhog/smtp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

github.com/mailhog/smtp implements an SMTP server state machine.

It attempts to encapsulate as much of the SMTP protocol (plus its extensions) as possiblewithout compromising configurability or requiring specific backend implementations.

proto:=NewProtocol()reply:=proto.Start()reply=proto.ProcessCommand("EHLO localhost")// ...

SeeMailHog-Server andMailHog-MTA for example implementations.

Commands and replies

Interaction with the state machine is via:

  • theParse function
  • theProcessCommand andProcessData functions

You can mix the use of all three functions as necessary.

Parse

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.

If any unprocessed data is returned,Parse should becalled again to process then next command.

text:="EHLO localhost\r\nMAIL FROM:<test>\r\nDATA\r\nTest\r\n.\r\n"varreply*smtp.Replyfor {text,reply=proto.Parse(text)iflen(text)==0 {break  }}

ProcessCommand and ProcessData

ProcessCommand should be used for an already parsed command (i.e., a completeSMTP "line" excluding the line ending).

ProcessData should be used if the protocol is inDATA state.

reply=proto.ProcessCommand("EHLO localhost")reply=proto.ProcessCommand("MAIL FROM:<test>")reply=proto.ProcessCommand("DATA")reply=proto.ProcessData("Test\r\n.\r\n")

Hooks

The state machine provides hooks to manipulate its behaviour.

SeeGoDoc for more information.

HookDescription
LogHandlerCalled for every log message
MessageReceivedHandlerCalled for each message received
ValidateSenderHandlerCalled after MAIL FROM
ValidateRecipientHandlerCalled after RCPT TO
ValidateAuthenticationHandlerCalled after AUTH
SMTPVerbFilterCalled for every SMTP command processed
TLSHandlerCallback mashup called after STARTTLS
GetAuthenticationMechanismsHandlerCalled for each EHLO command

Behaviour flags

The state machine also exports variables to control its behaviour:

SeeGoDoc for more information.

VariableDescription
RejectBrokenRCPTSyntaxReject non-conforming RCPT syntax
RejectBrokenMAILSyntaxReject non-conforming MAIL syntax
RequireTLSRequire STARTTLS before other commands
MaximumRecipientsMaximum recipients per message
MaximumLineLengthMaximum length of SMTP line

Licence

Copyright ©‎ 2014-2015, Ian Kent (http://iankent.uk)

Released under MIT license, seeLICENSE for details.

About

MailHog SMTP Protocol

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp