mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-24 06:30:49 +01:00
Winni Neessen
0b105048e6
Clarify the documentation for WriteToTempFile to better explain its functionality, ensure consistency, and detail its return values.
30 lines
806 B
Go
30 lines
806 B
Go
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build go1.17
|
|
// +build go1.17
|
|
|
|
package mail
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// WriteToTempFile creates a temporary file and writes the Msg content to this file.
|
|
//
|
|
// This method generates a temporary file with a ".eml" extension, writes the Msg to it, and returns the
|
|
// filename of the created temporary file.
|
|
//
|
|
// Returns:
|
|
// - A string representing the filename of the temporary file.
|
|
// - An error if the file creation or writing process fails.
|
|
func (m *Msg) WriteToTempFile() (string, error) {
|
|
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())
|
|
}
|