From 4e294699d3c673d6b31ef1180c75530f2852189b Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Sun, 18 Jan 2026 03:00:48 +0000 Subject: [PATCH] Initial test email works. --- comms/email.go | 27 +++++++++++++-------------- config/config.go | 35 ++++++++++++++++++++--------------- public-report/quick.go | 34 ++++++++++++++++++---------------- 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/comms/email.go b/comms/email.go index a31c145a..4c9de747 100644 --- a/comms/email.go +++ b/comms/email.go @@ -13,22 +13,22 @@ import ( type AttachmentRequest struct { Filename string `json:"filename"` - Content string `json:"content"` + Content string `json:"content"` } type EmailRequest struct { - From string `json:"from"` - To string `json:"to"` - CC []string `json:"cc,omitempty"` - BCC []string `json:"bcc,omitempty"` - Subject string `json:"subject"` - Text string `json:"text"` - HTML string `json:"html,omitempty"` + From string `json:"from"` + To string `json:"to"` + CC []string `json:"cc,omitempty"` + BCC []string `json:"bcc,omitempty"` + Subject string `json:"subject"` + Text string `json:"text"` + HTML string `json:"html,omitempty"` Attachments []AttachmentRequest `json:"attachments,omitempty"` - Sender string `json:"sender"` - ReplyTo string `json:"replyTo,omitempty"` - InReplyTo string `json:"inReplyTo,omitempty"` - References []string `json:"references,omitempty"` + Sender string `json:"sender"` + ReplyTo string `json:"replyTo,omitempty"` + InReplyTo string `json:"inReplyTo,omitempty"` + References []string `json:"references,omitempty"` } type EmailResponse struct { @@ -42,7 +42,6 @@ func SendEmail(email EmailRequest) error { if err != nil { return fmt.Errorf("Failed to marshal email request: %w", err) } - //payload := strings.NewReader("{\n \"from\": \"\",\n \"to\": \"\",\n \"cc\": \"\",\n \"bcc\": \"\",\n \"subject\": \"\",\n \"text\": \"\",\n \"html\": \"\",\n \"attachments\": [\n {}\n ],\n \"sender\": \"\",\n \"replyTo\": \"\",\n \"inReplyTo\": \"\",\n \"references\": \"\",\n \"attachDataUrls\": true,\n \"watchHtml\": \"\",\n \"amp\": \"\",\n \"icalEvent\": {},\n \"alternatives\": [\n {}\n ],\n \"encoding\": \"\",\n \"raw\": \"\",\n \"textEncoding\": \"quoted-printable\",\n \"priority\": \"high\",\n \"headers\": {\"ANY_ADDITIONAL_PROPERTY\": \"anything\"},\n \"messageId\": \"\",\n \"date\": \"\",\n \"list\": {},\n \"requireTLS\": true\n}") req, _ := http.NewRequest("POST", url, bytes.NewReader(payload)) req.SetBasicAuth(config.ForwardEmailAPIToken, "") @@ -53,6 +52,6 @@ func SendEmail(email EmailRequest) error { defer res.Body.Close() body, _ := io.ReadAll(res.Body) - log.Info().Str("status", res.Status).Str("request_body", string(payload)).Str("response_body", string(body)).Msg("Attempted to send email") + log.Info().Str("status", res.Status).Str("response_body", string(body)).Msg("Attempted to send email") return nil } diff --git a/config/config.go b/config/config.go index e4a7879c..1bd04286 100644 --- a/config/config.go +++ b/config/config.go @@ -8,24 +8,25 @@ import ( ) var ( - Bind string - ClientID string - ClientSecret string - Environment string - FilesDirectoryPublic string - FilesDirectoryUser string + Bind string + ClientID string + ClientSecret string + Environment string + FilesDirectoryPublic string + FilesDirectoryUser string FieldseekerSchemaDirectory string - ForwardEmailAPIToken string + ForwardEmailAPIToken string + ForwardEmailReportAddress string ForwardEmailReportPassword string ForwardEmailReportUsername string - MapboxToken string - PGDSN string - URLReport string - URLSync string - URLTegola string - VoipMSPassword string - VoipMSNumber string - VoipMSUsername string + MapboxToken string + PGDSN string + URLReport string + URLSync string + URLTegola string + VoipMSPassword string + VoipMSNumber string + VoipMSUsername string ) // Build the ArcGIS authorization URL with PKCE @@ -93,6 +94,10 @@ func Parse() error { if FilesDirectoryUser == "" { return fmt.Errorf("You must specify a non-empty FILES_DIRECTORY_USER") } + ForwardEmailReportAddress = os.Getenv("FORWARDEMAIL_REPORT_ADDRESS") + if ForwardEmailReportAddress == "" { + return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_REPORT_ADDRESS") + } ForwardEmailAPIToken = os.Getenv("FORWARDEMAIL_API_TOKEN") if ForwardEmailAPIToken == "" { return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_API_TOKEN") diff --git a/public-report/quick.go b/public-report/quick.go index ef686783..78cb5d9f 100644 --- a/public-report/quick.go +++ b/public-report/quick.go @@ -7,6 +7,7 @@ import ( "time" "github.com/Gleipnir-Technology/nidus-sync/comms" + "github.com/Gleipnir-Technology/nidus-sync/config" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" @@ -129,19 +130,21 @@ func postQuick(w http.ResponseWriter, r *http.Request) { return } log.Info().Int("len", len(images)).Msg("saved uploads") - setters := make([]*models.PublicreportQuickImageSetter, 0) - for _, image := range images { - setters = append(setters, &models.PublicreportQuickImageSetter{ - ImageID: omit.From(int32(image.ID)), - QuickID: omit.From(int32(quick.ID)), - }) + if len(images) > 0 { + setters := make([]*models.PublicreportQuickImageSetter, 0) + for _, image := range images { + setters = append(setters, &models.PublicreportQuickImageSetter{ + ImageID: omit.From(int32(image.ID)), + QuickID: omit.From(int32(quick.ID)), + }) + } + _, err = models.PublicreportQuickImages.Insert(bob.ToMods(setters...)).Exec(ctx, tx) + if err != nil { + respondError(w, "Failed to save reference to images", err, http.StatusInternalServerError) + return + } + log.Info().Int("len", len(images)).Msg("saved uploads") } - _, err = models.PublicreportQuickImages.Insert(bob.ToMods(setters...)).Exec(ctx, tx) - if err != nil { - respondError(w, "Failed to save reference to images", err, http.StatusInternalServerError) - return - } - log.Info().Int("len", len(images)).Msg("saved uploads") tx.Commit(ctx) http.Redirect(w, r, fmt.Sprintf("/quick-submit-complete?report=%s", u), http.StatusFound) } @@ -180,10 +183,10 @@ func postRegisterNotifications(w http.ResponseWriter, r *http.Request) { } if email != "" { comms.SendEmail(comms.EmailRequest{ - From: "website@mosquitoes.online", - To: email, + From: config.ForwardEmailReportAddress, + To: email, Subject: "test email", - Text: "This is just testing that I can send email", + Text: "This is just testing that I can send email", }) } if phone != "" { @@ -198,4 +201,3 @@ func postRegisterNotifications(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, fmt.Sprintf("/register-notifications-complete?report=%s", report_id), http.StatusFound) } } -