Skip to content

Instantly share code, notes, and snippets.

@rahulvramesh
Created June 20, 2019 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulvramesh/85690b36e65fbfcdd41848e434bd6967 to your computer and use it in GitHub Desktop.
Save rahulvramesh/85690b36e65fbfcdd41848e434bd6967 to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"net"
"time"
"github.com/Sirupsen/logrus"
"github.com/davecgh/go-spew/spew"
"github.com/corpix/smtpd"
)
type smtpServer struct{}
func (s *smtpServer) ServeSMTP(c net.Conn, e *smtpd.Envelope) {
logrus.Infof(
"Received message from %s those envelope: %s\n",
c.RemoteAddr(),
spew.Sdump(e),
)
msg, err := e.Message()
if err != nil {
panic(err)
}
body, err := ioutil.ReadAll(msg.Body)
if err != nil {
panic(err)
}
logrus.Infof("Message body: %s\n", body)
}
func main() {
var err error
c, err := net.Listen("tcp", "127.0.0.1:25")
if err != nil {
panic(err)
}
for {
err = smtpd.Serve(c, &smtpServer{})
if err != nil {
logrus.Error(err)
time.Sleep(1 * time.Second)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment