From a3f982329383dbbe9069a5da4994689af639e428 Mon Sep 17 00:00:00 2001 From: arzumify Date: Thu, 21 Nov 2024 19:35:30 +0000 Subject: [PATCH] Fixed the broken module name --- examples/main.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 examples/main.go diff --git a/examples/main.go b/examples/main.go new file mode 100644 index 0000000..0e37e9d --- /dev/null +++ b/examples/main.go @@ -0,0 +1,55 @@ +package main + +import ( + "fmt" + "github.com/google/uuid" + "net" + "smtp" +) + +// DatabaseBackend is a smtp.DatabaseBackend implementation that always returns true for CheckUser and prints the mail data to stdout. +var DatabaseBackend = smtp.DatabaseBackend{ + CheckUser: func(address *smtp.Address) (bool, error) { + return true, nil + }, + WriteMail: func(mail *smtp.Mail) (uuid.UUID, error) { + fmt.Println(string(mail.Data)) + return uuid.New(), nil + }, +} + +// AuthenticationBackend is a smtp.AuthenticationBackend implementation that always returns a fixed address for Authenticate. +var AuthenticationBackend = smtp.AuthenticationBackend{ + Authenticate: func(authCommand string) (*smtp.Address, error) { + return &smtp.Address{ + Name: "test", + Address: "example.org", + }, nil + }, +} + +func main() { + go func() { + // Serve on the server-to-server port + listener, err := net.Listen("tcp", ":25") + if err != nil { + panic(err) + } + receiver := smtp.NewReceiver(listener, "localhost", []string{"localhost", "127.0.0.1", "0.0.0.0", "example.org", "192.168.1.253"}, false, DatabaseBackend, AuthenticationBackend, nil) + err = receiver.Serve() + panic(err) + }() + go func() { + // Serve on the submission port + listener, err := net.Listen("tcp", ":587") + if err != nil { + panic(err) + } + receiver := smtp.NewReceiver(listener, "localhost", []string{"localhost", "127.0.0.1", "0.0.0.0", "cta.social"}, false, DatabaseBackend, AuthenticationBackend, nil) + err = receiver.Serve() + panic(err) + }() + + // Block forever + select {} +} diff --git a/go.mod b/go.mod index a98c213..2ef1932 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module smtp +module git.ailur.dev/ailur/smtp go 1.23