59 lines
2 KiB
Go
59 lines
2 KiB
Go
// verae-mailtest sends ONE verification-code email using SMTP_* env settings,
|
|
// to check delivery of the installer registration mailer. Server-side tool;
|
|
// not shipped in the Windows/macOS client.
|
|
//
|
|
// SMTP_USER=veraetimestamp@gmail.com SMTP_PASS=... verae-mailtest --to veraetimestamp@gmail.com --send
|
|
//
|
|
// Without --send it only renders the message (--preview DIR writes .txt/.html).
|
|
// The password and the generated code are never printed.
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/VeraeLLC/PrintToVeraeTimeStamp/internal/mailer"
|
|
)
|
|
|
|
func main() {
|
|
to := flag.String("to", "", "recipient (default: SMTP_USER, i.e. a self-send)")
|
|
name := flag.String("name", "George", "name used in the greeting")
|
|
send := flag.Bool("send", false, "actually send (otherwise preview only)")
|
|
preview := flag.String("preview", "", "write preview .txt/.html into this directory")
|
|
flag.Parse()
|
|
|
|
cfg, err := mailer.FromEnv()
|
|
if err != nil && *send {
|
|
fmt.Fprintln(os.Stderr, "config:", err)
|
|
os.Exit(2)
|
|
}
|
|
if *to == "" {
|
|
*to = cfg.User
|
|
}
|
|
code, err := mailer.NewCode()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
m := mailer.CodeEmail(*to, *name, code, 15, "the Verae installer (mailer test)")
|
|
if *preview != "" {
|
|
_ = os.MkdirAll(*preview, 0o755)
|
|
_ = os.WriteFile(filepath.Join(*preview, "code-email.txt"), []byte(m.Text), 0o644)
|
|
_ = os.WriteFile(filepath.Join(*preview, "code-email.html"), []byte(m.HTML), 0o644)
|
|
fmt.Println("preview written to", *preview, "(contains a random, unused test code)")
|
|
}
|
|
if !*send {
|
|
fmt.Println("not sending (pass --send).", cfg.String())
|
|
return
|
|
}
|
|
fmt.Printf("sending one test code email to %s via %s\n", mailer.MaskEmail(*to), cfg.String())
|
|
t0 := time.Now()
|
|
if err := (&mailer.SMTPSender{Cfg: cfg}).Send(m); err != nil {
|
|
fmt.Fprintln(os.Stderr, "send failed:", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Printf("sent OK in %.1fs (subject \"Your Verae verification code: *** ***\"; code not printed)\n", time.Since(t0).Seconds())
|
|
}
|