mirror of
https://github.com/1f349/lotus.git
synced 2024-11-09 22:52:53 +00:00
36 lines
594 B
Go
36 lines
594 B
Go
package smtp
|
|
|
|
import (
|
|
"github.com/emersion/go-message/mail"
|
|
"os/exec"
|
|
)
|
|
|
|
type Smtp struct {
|
|
Server string `yaml:"server"`
|
|
}
|
|
|
|
type Mail struct {
|
|
From *mail.Address
|
|
Body []byte
|
|
}
|
|
|
|
var execSendMail = func(from string) *exec.Cmd {
|
|
return exec.Command("/usr/lib/sendmail", "-f", from, "-t")
|
|
}
|
|
|
|
func (s *Smtp) Send(mail *Mail) error {
|
|
// start sendmail caller
|
|
sendMail := execSendMail(mail.From.String())
|
|
inPipe, err := sendMail.StdinPipe()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// write message body
|
|
_, err = inPipe.Write(mail.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return inPipe.Close()
|
|
}
|