diff --git a/email/email.go b/email/email.go new file mode 100644 index 0000000..0e22961 --- /dev/null +++ b/email/email.go @@ -0,0 +1,18 @@ +package email + +import ( + "bytes" + "fmt" + "os/exec" +) + +func SendLocalEmail(username, subject, body string) error { + cmd := exec.Command("/usr/sbin/sendmail", username) + cmd.Stdin = bytes.NewBufferString(fmt.Sprintf("Subject: %s\n\n%s", subject, body)) + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to send local email: %w", err) + } + + return nil +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..2bf02be --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "git.tilde.town/tildetown/town/email" + +func main() { + email.SendLocalEmail("vilmibm", "testing hi", "this is a body") +} diff --git a/town.go b/user/user.go similarity index 60% rename from town.go rename to user/user.go index 479c80a..8a7f639 100644 --- a/town.go +++ b/user/user.go @@ -1,9 +1,7 @@ -package town +package user import ( - "bytes" "fmt" - "os/exec" "os/user" ) @@ -28,14 +26,3 @@ func IsAdmin(u user.User) (bool, error) { return false, nil } - -func SendLocalEmail(username, subject, body string) error { - cmd := exec.Command("/usr/sbin/sendmail", "-s", subject, username) - cmd.Stdin = bytes.NewBufferString(body) - - if err := cmd.Run(); err != nil { - return fmt.Errorf("failed to send local email: %w", err) - } - - return nil -}