Added WriteToSendmailWithCommand which is more generic and takes a command to sendmail

The code of WriteToSendmail has been refactored to return the new WriteToSendmailWithCommand using SendmailPath
This commit is contained in:
Winni Neessen 2022-03-18 21:07:07 +01:00
parent 00264b6f70
commit 3c642be4eb
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

10
msg.go
View file

@ -490,11 +490,17 @@ func (m *Msg) appendFile(c []*File, f *File, o ...FileOption) []*File {
return append(c, f)
}
// WriteToSendmail returns WriteToSendmailWithContext with a default timeout of 5 seconds
// WriteToSendmail returns WriteToSendmailWithCommand with a default sendmail path
func (m *Msg) WriteToSendmail() error {
return m.WriteToSendmailWithCommand(SendmailPath)
}
// WriteToSendmailWithCommand returns WriteToSendmailWithContext with a default timeout
// of 5 seconds and a given sendmail path
func (m *Msg) WriteToSendmailWithCommand(sp string) error {
tctx, tcfn := context.WithTimeout(context.Background(), time.Second*5)
defer tcfn()
return m.WriteToSendmailWithContext(tctx, SendmailPath)
return m.WriteToSendmailWithContext(tctx, sp)
}
// WriteToSendmailWithContext opens an pipe to the local sendmail binary and tries to send the