I want to send a CSV attachment without saving the attached data to a hard drive first. I'm using gomail throughout my code. How can I attach data directly from memory using gomail?
Asked
Active
Viewed 604 times
1 Answers
4
You can use the FileSetting functions that gomail provides
csv, _ := gocsv.MarshalBytes(someData) // ignoring the error for the example
email := gomail.NewMessage()
email.Attach(
fmt.Sprintf("Filename.csv"),
gomail.SetCopyFunc(func(w io.Writer) error {
_, err := w.Write(csv)
return err
}),
gomail.SetHeader(map[string][]string{"Content-Type": {"text/csv"}}),
)

nobody
- 1,144
- 1
- 10
- 20