MailHog SMTP Protocol

MailHog SMTP Protocol GoDoc Build Status

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.

Commands and replies

Interaction with the state machine is via:

  • the Parse function
  • the ProcessCommand and ProcessData 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 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 and ProcessData

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")

Hooks

The state machine provides hooks to manipulate its behaviour.

See GoDoc for more information.

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

Behaviour flags

The state machine also exports variables to control its behaviour:

See GoDoc for more information.

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

Licence

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

Released under MIT license, see LICENSE for details.

Owner
MailHog
Web and API based SMTP testing
MailHog
Comments
  • scripted telnet doesn't work

    scripted telnet doesn't work

    telnet 127.0.0.1 25 << EOF
    HELO cloudflare.com
    MAIL FROM:<[email protected]>
    RCPT TO:<[email protected]>
    DATA
    Body of email.
    .
    QUIT
    EOF
    

    I tested this with postfix and other mtas with no issues.

  • support MAIL command with a null

    support MAIL command with a null

    MAIL command with a null is required in rfc5321 as shown below.

    https://tools.ietf.org/html/rfc5321#section-3.6.3

    One way to prevent loops in error reporting is to specify a null reverse-path
    in the MAIL command of a notification message.
    When such a message is transmitted, the reverse-path MUST be set to null
    (see   Section 4.5.5 for additional discussion).
    A MAIL command with a null reverse-path appears as follows:
    
      MAIL FROM:<>
    

    In fact, Postfix bounce emails have MAIL command set to "FROM:<>". But, MailHog validation judges "FROM:<>" as an error. Therefore, Postfix bounce email cannot be received by MailHog.

    This Pull Request allows you to receive Postfix bounce email by support MAIL command with a null.

  • RSET clears EHLO

    RSET clears EHLO

    When issuing a RSET command, mailhog will reset the SMTPMessage. This will also clear the original Helo value. Since a "real" mail server will usually keep the smtp HELO value intact, would it be worthwhile to also have that behaviour here?

    https://github.com/mailhog/smtp/blob/0c4e9b7e0625fec61d0c30d7b2f6c62852be6c54/protocol.go#L233

  • Is this abandoned?

    Is this abandoned?

    I've had an open issue (#2), and two open PRs (#3, #4) for over a year, now, with no response here. Is there any hope the changes will ever be responded to?

  • Hooks for SMTP extensions

    Hooks for SMTP extensions

    It would be really useful if SMTP extensions could be supported. This would include replying with the added SMTP extensions in the EHLO response, and providing hooks so extensions can add functionality.

    I'm attempting to support the SMTP Extensions for Internationalized Email (RFC 6531), but that's not possible with the current implementation.

Related tags
Lightweight SMTP client written in Go

Hectane Hectane is both a Go package providing an SMTP queue for sending emails and a standalone application that exposes this functionality via an HT

Nov 23, 2022
Web and API based SMTP testing
Web and API based SMTP testing

MailHog Inspired by MailCatcher, easier to install. Download and run MailHog Configure your outgoing SMTP server View your outgoing email in a web UI

Jan 4, 2023
:incoming_envelope: Simple email interface across multiple service providers (ses, postmark, mandrill, smtp)
:incoming_envelope: Simple email interface across multiple service providers (ses, postmark, mandrill, smtp)

go-mail Lightweight email package with multi-provider support (ses, mandrill, postmark) Table of Contents Installation Documentation Examples & Tests

Dec 10, 2022
envio de email via SMTP com anexo usando Go

gosendmail - SMTP This repo is a simple net/smtp abstraction for sending emails using SMTP. With it we can send emails With copy, with blind copy and

Aug 18, 2022
Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.
Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.

Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.

Jan 1, 2023
golang honeypot smtp server
golang honeypot smtp server

honeygogo-smtp standalone honeypot A lightweight SMTP honeypot server written in Go, leveraging go-smtp. A stand alone version of a module from honeyg

May 4, 2022
Simple SMTP Server for Testing

go-smtptester Simple SMTP Server for Testing. How it works All received mails are saved in a sync.Map with a key: From+Recipient1+Recipient2 Mails to

Nov 18, 2021
Simple tool to test SMTP mail send with various settings including TLS1.1 downgrade

smtptest Simple tool to test SMTP mail send with various settings including TLS1.1 downgrade All settings are configurable in the config.yaml file ser

Sep 19, 2022
Pretty wrapper for sending email using go net/smtp

Emailer A pretty wrapper around go net/smtp send multiple email using single client func main() { var client *emailer.Client var clientX sync.Mute

Mar 23, 2022
Golang package for send email. Support keep alive connection, TLS and SSL. Easy for bulk SMTP.

Go Simple Mail The best way to send emails in Go with SMTP Keep Alive and Timeout for Connect and Send. IMPORTANT Examples in this README are for v2.2

Jan 8, 2023
Lightweight SMTP client written in Go

Hectane Hectane is both a Go package providing an SMTP queue for sending emails and a standalone application that exposes this functionality via an HT

Nov 23, 2022
Web and API based SMTP testing
Web and API based SMTP testing

MailHog Inspired by MailCatcher, easier to install. Download and run MailHog Configure your outgoing SMTP server View your outgoing email in a web UI

Jan 4, 2023
:incoming_envelope: Simple email interface across multiple service providers (ses, postmark, mandrill, smtp)
:incoming_envelope: Simple email interface across multiple service providers (ses, postmark, mandrill, smtp)

go-mail Lightweight email package with multi-provider support (ses, mandrill, postmark) Table of Contents Installation Documentation Examples & Tests

Dec 10, 2022
envio de email via SMTP com anexo usando Go

gosendmail - SMTP This repo is a simple net/smtp abstraction for sending emails using SMTP. With it we can send emails With copy, with blind copy and

Aug 18, 2022
Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.
Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.

Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.

Jan 1, 2023
golang honeypot smtp server
golang honeypot smtp server

honeygogo-smtp standalone honeypot A lightweight SMTP honeypot server written in Go, leveraging go-smtp. A stand alone version of a module from honeyg

May 4, 2022
Simple SMTP Server for Testing

go-smtptester Simple SMTP Server for Testing. How it works All received mails are saved in a sync.Map with a key: From+Recipient1+Recipient2 Mails to

Nov 18, 2021
Simple tool to test SMTP mail send with various settings including TLS1.1 downgrade

smtptest Simple tool to test SMTP mail send with various settings including TLS1.1 downgrade All settings are configurable in the config.yaml file ser

Sep 19, 2022
Pretty wrapper for sending email using go net/smtp

Emailer A pretty wrapper around go net/smtp send multiple email using single client func main() { var client *emailer.Client var clientX sync.Mute

Mar 23, 2022
This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.
This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

Oct 5, 2022