Created
June 20, 2019 07:53
-
-
Save rahulvramesh/85690b36e65fbfcdd41848e434bd6967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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