basic common app packages
This commit is contained in:
35
email/transport.go
Normal file
35
email/transport.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"code.patial.tech/go/appcore/open"
|
||||
)
|
||||
|
||||
type Transport interface {
|
||||
Send(*Message) error
|
||||
}
|
||||
|
||||
// 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 := time.Now().Format("20060102T150405999")
|
||||
file := filepath.Join(dir, id+".html")
|
||||
|
||||
if err := os.WriteFile(file, []byte(msg.HtmlBody), 0440); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return open.WithDefaultApp(file)
|
||||
}
|
Reference in New Issue
Block a user