Begin implementing RFC5321

This commit is contained in:
Ian Kent 2014-04-16 23:59:25 +01:00
parent 0e679e1798
commit c27e0a3c7c
3 changed files with 40 additions and 10 deletions

View file

@ -1,8 +0,0 @@
package mailhog
type Message struct {
From string
To string
Data []byte
Helo string
}

33
mailhog/smtp/smtp.go Normal file
View file

@ -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
}
}

View file

@ -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))
}
}