2022-06-17 15:05:54 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-06-09 09:57:01 +02:00
|
|
|
//go:build !go1.17
|
|
|
|
// +build !go1.17
|
|
|
|
|
|
|
|
package mail
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
2022-06-09 10:11:37 +02:00
|
|
|
// WriteToTempFile will create a temporary file and output the Msg to this file
|
2022-06-09 09:57:01 +02:00
|
|
|
// The method will return the filename of the temporary file
|
2022-06-09 10:11:37 +02:00
|
|
|
func (m *Msg) WriteToTempFile() (string, error) {
|
2022-06-09 09:57:01 +02:00
|
|
|
f, err := ioutil.TempFile("", "go-mail_*.eml")
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("failed to create output file: %w", err)
|
|
|
|
}
|
|
|
|
defer func() { _ = f.Close() }()
|
|
|
|
return f.Name(), m.WriteToFile(f.Name())
|
|
|
|
}
|