-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathmsg_totmpfile.go
More file actions
27 lines (24 loc) 路 760 Bytes
/
Copy pathmsg_totmpfile.go
File metadata and controls
27 lines (24 loc) 路 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-FileCopyrightText: The go-mail Authors
//
// SPDX-License-Identifier: MIT
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())
}