2023-01-15 16:14:19 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
2022-06-17 15:05:54 +02:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-06-09 09:57:01 +02:00
|
|
|
//go:build go1.17
|
|
|
|
// +build go1.17
|
|
|
|
|
|
|
|
package mail
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
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 := os.CreateTemp("", "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())
|
|
|
|
}
|