diff --git a/mailhog/smtp.go b/mailhog/smtp.go deleted file mode 100644 index c58b1b9..0000000 --- a/mailhog/smtp.go +++ /dev/null @@ -1,8 +0,0 @@ -package mailhog - -type Message struct { - From string - To string - Data []byte - Helo string -} diff --git a/mailhog/smtp/smtp.go b/mailhog/smtp/smtp.go new file mode 100644 index 0000000..ea133aa --- /dev/null +++ b/mailhog/smtp/smtp.go @@ -0,0 +1,33 @@ +package smtp + +// http://www.rfc-editor.org/rfc/rfc5321.txt + +import ( + "log" + "net" +) + +type Session struct { + conn *net.TCPConn +} + +type Message struct { + From string + To string + Data []byte + Helo string +} + +func StartSession(conn *net.TCPConn) (*Session) { + conv := &Session{conn} + conv.Begin() + return conv +} + +func (c Session) Begin() { + _, err := c.conn.Write([]byte("220 Go-MailHog\n")) + if err != nil { + log.Printf("Failed writing to socket: %s", err) + return + } +} diff --git a/main.go b/main.go index df70353..c5f11d7 100644 --- a/main.go +++ b/main.go @@ -4,19 +4,24 @@ import ( "flag" "log" "net" + "github.com/ian-kent/MailHog/mailhog/smtp" ) var conf = map[string]string { "BIND_ADDRESS": "0.0.0.0:1025", + "HOSTNAME": "mailhog.example", } func config() { - var listen string + var listen, hostname string flag.StringVar(&listen, "listen", "0.0.0.0:1025", "Bind interface and port, e.g. 0.0.0.0:1025 or just :1025") + flag.StringVar(&hostname, "hostname", "mailhog.example", "Hostname for EHLO/HELO response, e.g. mailhog.example") + flag.Parse() conf["BIND_ADDRESS"] = listen + conf["HOSTNAME"] = hostname } func main() { @@ -33,7 +38,7 @@ func main() { } defer conn.Close() - go accept(conn) + go smtp.StartSession(conn.(*net.TCPConn)) } }