ptr, ref and deref funcs response, use fmt.Fprint(f) validate, few new funcs
31 lines
664 B
Go
31 lines
664 B
Go
package email
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"code.patial.tech/go/appcore/open"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// DumpToTemp transport is for development environment to ensure emails are renderd as HTML ok
|
|
// once dump operation is done it will try to open the html with default app for html
|
|
type DumpToTemp struct{}
|
|
|
|
func (DumpToTemp) Send(msg *Message) error {
|
|
// validate msg first
|
|
if err := msg.Validate(); err != nil {
|
|
return err
|
|
}
|
|
|
|
dir := os.TempDir()
|
|
id, _ := uuid.NewV7()
|
|
file := filepath.Join(dir, id.String()+".html")
|
|
|
|
if err := os.WriteFile(file, []byte(msg.HtmlBody), 0440); err != nil {
|
|
return err
|
|
}
|
|
|
|
return open.WithDefaultApp(file)
|
|
}
|