2025-10-03 00:12:00 +05:30
|
|
|
package email
|
|
|
|
|
|
|
|
|
|
import (
|
2026-02-20 16:38:24 +05:30
|
|
|
"fmt"
|
2025-10-03 00:12:00 +05:30
|
|
|
"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()
|
2026-02-20 16:38:24 +05:30
|
|
|
id, err := uuid.NewV7()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("email: failed to generate UUID: %w", err)
|
|
|
|
|
}
|
2025-10-03 00:12:00 +05:30
|
|
|
file := filepath.Join(dir, id.String()+".html")
|
|
|
|
|
|
|
|
|
|
if err := os.WriteFile(file, []byte(msg.HtmlBody), 0440); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return open.WithDefaultApp(file)
|
|
|
|
|
}
|