restructure

pull/1/head v0.0.2
vilmibm 2021-03-23 21:58:17 +00:00
parent bd0fb8be77
commit b5caa1355c
3 changed files with 26 additions and 14 deletions

18
email/email.go 100644
View File

@ -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
}

7
main.go 100644
View File

@ -0,0 +1,7 @@
package main
import "git.tilde.town/tildetown/town/email"
func main() {
email.SendLocalEmail("vilmibm", "testing hi", "this is a body")
}

View File

@ -1,9 +1,7 @@
package town package user
import ( import (
"bytes"
"fmt" "fmt"
"os/exec"
"os/user" "os/user"
) )
@ -28,14 +26,3 @@ func IsAdmin(u user.User) (bool, error) {
return false, nil 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
}