parent
bd0fb8be77
commit
b5caa1355c
|
@ -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
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "git.tilde.town/tildetown/town/email"
|
||||
|
||||
func main() {
|
||||
email.SendLocalEmail("vilmibm", "testing hi", "this is a body")
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue