town/email/email.go

19 lines
364 B
Go
Raw Permalink Normal View History

2021-03-23 21:58:17 +00:00
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
}