Original code from mailhog
data
github.com/mailhog/data
implements a data library
Copyright © 2014-2015, Ian Kent (http://iankent.uk)
Released under MIT license, see LICENSE for details.
http
github.com/mailhog/http
provides HTTP utilities used by MailHog-UI and MailHog-Server.
Copyright © 2014-2015, Ian Kent (http://iankent.uk)
Released under MIT license, see LICENSE for details.
mhsendmail
A sendmail replacement which forwards mail to an SMTP server.
> go get github.com/mailhog/mhsendmail
> mhsendmail [email protected] <<EOF
From: App <[email protected]>
To: Test <[email protected]>
Subject: Test message
Some content!
EOF
You can also set the from address (for SMTP MAIL FROM
):
./mhsendmail --from="[email protected]" [email protected] ...
Or pass in multiple recipients:
./mhsendmail --from="[email protected]" [email protected] [email protected] ...
Or override the destination SMTP server:
./mhsendmail --smtp-addr="localhost:1026" [email protected] ...
To use from php.ini
sendmail_path = /usr/local/bin/mhsendmail
Copyright © 2015 - 2016, Ian Kent (http://iankent.uk)
Released under MIT license, see LICENSE for details.
server
MailHog-Server is the MailHog SMTP and HTTP API server.
Copyright © 2014 - 2016, Ian Kent (http://iankent.uk)
Released under MIT license, see LICENSE for details.
smtp
github.com/mailhog/smtp
implements an SMTP server state machine.
It attempts to encapsulate as much of the SMTP protocol (plus its extensions) as possible without compromising configurability or requiring specific backend implementations.
proto := NewProtocol()
reply := proto.Start()
reply = proto.ProcessCommand("EHLO localhost")
// ...
See MailHog-Server and MailHog-MTA for example implementations.
Interaction with the state machine is via:
- the
Parse
function - the
ProcessCommand
andProcessData
functions
You can mix the use of all three functions as necessary.
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 be
called again to process then next command.
text := "EHLO localhost\r\nMAIL FROM:<test>\r\nDATA\r\nTest\r\n.\r\n"
var reply *smtp.Reply
for {
text, reply = proto.Parse(text)
if len(text) == 0 {
break
}
}
ProcessCommand
should be used for an already parsed command (i.e., a complete
SMTP "line" excluding the line ending).
ProcessData
should be used if the protocol is in DATA
state.
reply = proto.ProcessCommand("EHLO localhost")
reply = proto.ProcessCommand("MAIL FROM:<test>")
reply = proto.ProcessCommand("DATA")
reply = proto.ProcessData("Test\r\n.\r\n")
The state machine provides hooks to manipulate its behaviour.
Hook | Description |
---|---|
LogHandler | Called for every log message |
MessageReceivedHandler | Called for each message received |
ValidateSenderHandler | Called after MAIL FROM |
ValidateRecipientHandler | Called after RCPT TO |
ValidateAuthenticationHandler | Called after AUTH |
SMTPVerbFilter | Called for every SMTP command processed |
TLSHandler | Callback mashup called after STARTTLS |
GetAuthenticationMechanismsHandler | Called for each EHLO command |
The state machine also exports variables to control its behaviour:
Variable | Description |
---|---|
RejectBrokenRCPTSyntax | Reject non-conforming RCPT syntax |
RejectBrokenMAILSyntax | Reject non-conforming MAIL syntax |
RequireTLS | Require STARTTLS before other commands |
MaximumRecipients | Maximum recipients per message |
MaximumLineLength | Maximum length of SMTP line |
Copyright © 2014-2015, Ian Kent (http://iankent.uk)
Released under MIT license, see LICENSE for details.
storage
github.com/mailhog/storage
implements MailHog storage backends:
- In-memory
- MongoDB
You should implement storage.Storage
interface to provide your
own storage backend.
Copyright © 2014 - 2016, Ian Kent (http://iankent.uk)
Released under MIT license, see LICENSE for details.
ui
MailHog-UI is the MailHog web based user interface.
Copyright © 2014 - 2016, Ian Kent (http://iankent.uk)
Released under MIT license, see LICENSE for details.