mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-23 22:34:04 +00:00
Begin implementing RFC5321
This commit is contained in:
parent
0e679e1798
commit
c27e0a3c7c
3 changed files with 40 additions and 10 deletions
|
@ -1,8 +0,0 @@
|
|||
package mailhog
|
||||
|
||||
type Message struct {
|
||||
From string
|
||||
To string
|
||||
Data []byte
|
||||
Helo string
|
||||
}
|
33
mailhog/smtp/smtp.go
Normal file
33
mailhog/smtp/smtp.go
Normal 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
|
||||
}
|
||||
}
|
9
main.go
9
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue