mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 05:40:50 +01:00
#18: Added Msg.WriteToFile which allows storing the Msg in a file
This commit is contained in:
parent
d10dc92518
commit
95100545d6
1 changed files with 15 additions and 0 deletions
15
msg.go
15
msg.go
|
@ -593,6 +593,21 @@ func (m *Msg) appendFile(c []*File, f *File, o ...FileOption) []*File {
|
||||||
return append(c, f)
|
return append(c, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteToFile stores the Msg as file on disk. It will try to create the given filename
|
||||||
|
// Already existing files will be overwritten
|
||||||
|
func (m *Msg) WriteToFile(n string) error {
|
||||||
|
f, err := os.Create(n)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create output file: %w", err)
|
||||||
|
}
|
||||||
|
defer func() { _ = f.Close() }()
|
||||||
|
_, err = m.WriteTo(f)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to write to output file: %w", err)
|
||||||
|
}
|
||||||
|
return f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
// WriteToSendmail returns WriteToSendmailWithCommand with a default sendmail path
|
// WriteToSendmail returns WriteToSendmailWithCommand with a default sendmail path
|
||||||
func (m *Msg) WriteToSendmail() error {
|
func (m *Msg) WriteToSendmail() error {
|
||||||
return m.WriteToSendmailWithCommand(SendmailPath)
|
return m.WriteToSendmailWithCommand(SendmailPath)
|
||||||
|
|
Loading…
Reference in a new issue