summaryrefslogtreecommitdiffhomepage
path: root/lib/email
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-09-13 13:01:48 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-09-13 13:01:48 +0200
commit548090e67f66acf84385c4152ca464e52d3e3319 (patch)
tree9b6de528bd7b0aa63362fa83f5c8e6a97f68a5d8 /lib/email
parenta1d809960bee74df19c7e5fc34ffd1e4757cfdcb (diff)
Migrate away from templ and towards html/template
Diffstat (limited to 'lib/email')
-rw-r--r--lib/email/email.go74
1 files changed, 0 insertions, 74 deletions
diff --git a/lib/email/email.go b/lib/email/email.go
deleted file mode 100644
index 16ba492..0000000
--- a/lib/email/email.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package email
-
-import (
- "crypto/tls"
- "fmt"
- "math/rand/v2"
- "net/smtp"
- "strconv"
- "time"
-)
-
-var Config struct {
- Host string
- Port int
- ToAddr, FromAddr string
- Password string
-}
-
-const emailTemplate = `From: %s
-To: %s
-Subject: %s
-Date: %s
-Content-Type: text/plain; charset=UTF-8
-MIME-Version: 1.0
-Message-ID: <%s>
-
-%s`
-
-func ServerError(fault error) error {
- msgid := strconv.FormatInt(rand.Int64(), 10) + "@" + Config.Host
- msg := fmt.Sprintf(emailTemplate, Config.FromAddr, Config.ToAddr,
- "Error Report", time.Now().Format(time.RFC1123Z), msgid, fault)
-
- tlsConfig := &tls.Config{
- InsecureSkipVerify: false,
- ServerName: Config.Host,
- }
-
- hostWithPort := Config.Host + ":" + strconv.Itoa(Config.Port)
- conn, err := tls.Dial("tcp", hostWithPort, tlsConfig)
- if err != nil {
- return err
- }
-
- client, err := smtp.NewClient(conn, Config.Host)
- if err != nil {
- return err
- }
- defer client.Close()
-
- auth := smtp.PlainAuth("", Config.FromAddr, Config.Password, Config.Host)
- if err := client.Auth(auth); err != nil {
- return err
- }
-
- if err := client.Mail(Config.FromAddr); err != nil {
- return err
- }
-
- if err := client.Rcpt(Config.ToAddr); err != nil {
- return err
- }
-
- wc, err := client.Data()
- if err != nil {
- return err
- }
- defer wc.Close()
-
- if _, err = wc.Write([]byte(msg)); err != nil {
- return err
- }
- return nil
-}