Initial test email works.

This commit is contained in:
Eli Ribble 2026-01-18 03:00:48 +00:00
parent 7abaebe496
commit 4e294699d3
No known key found for this signature in database
3 changed files with 51 additions and 45 deletions

View file

@ -13,22 +13,22 @@ import (
type AttachmentRequest struct { type AttachmentRequest struct {
Filename string `json:"filename"` Filename string `json:"filename"`
Content string `json:"content"` Content string `json:"content"`
} }
type EmailRequest struct { type EmailRequest struct {
From string `json:"from"` From string `json:"from"`
To string `json:"to"` To string `json:"to"`
CC []string `json:"cc,omitempty"` CC []string `json:"cc,omitempty"`
BCC []string `json:"bcc,omitempty"` BCC []string `json:"bcc,omitempty"`
Subject string `json:"subject"` Subject string `json:"subject"`
Text string `json:"text"` Text string `json:"text"`
HTML string `json:"html,omitempty"` HTML string `json:"html,omitempty"`
Attachments []AttachmentRequest `json:"attachments,omitempty"` Attachments []AttachmentRequest `json:"attachments,omitempty"`
Sender string `json:"sender"` Sender string `json:"sender"`
ReplyTo string `json:"replyTo,omitempty"` ReplyTo string `json:"replyTo,omitempty"`
InReplyTo string `json:"inReplyTo,omitempty"` InReplyTo string `json:"inReplyTo,omitempty"`
References []string `json:"references,omitempty"` References []string `json:"references,omitempty"`
} }
type EmailResponse struct { type EmailResponse struct {
@ -42,7 +42,6 @@ func SendEmail(email EmailRequest) error {
if err != nil { if err != nil {
return fmt.Errorf("Failed to marshal email request: %w", err) 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, _ := http.NewRequest("POST", url, bytes.NewReader(payload))
req.SetBasicAuth(config.ForwardEmailAPIToken, "") req.SetBasicAuth(config.ForwardEmailAPIToken, "")
@ -53,6 +52,6 @@ func SendEmail(email EmailRequest) error {
defer res.Body.Close() defer res.Body.Close()
body, _ := io.ReadAll(res.Body) 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 return nil
} }

View file

@ -8,24 +8,25 @@ import (
) )
var ( var (
Bind string Bind string
ClientID string ClientID string
ClientSecret string ClientSecret string
Environment string Environment string
FilesDirectoryPublic string FilesDirectoryPublic string
FilesDirectoryUser string FilesDirectoryUser string
FieldseekerSchemaDirectory string FieldseekerSchemaDirectory string
ForwardEmailAPIToken string ForwardEmailAPIToken string
ForwardEmailReportAddress string
ForwardEmailReportPassword string ForwardEmailReportPassword string
ForwardEmailReportUsername string ForwardEmailReportUsername string
MapboxToken string MapboxToken string
PGDSN string PGDSN string
URLReport string URLReport string
URLSync string URLSync string
URLTegola string URLTegola string
VoipMSPassword string VoipMSPassword string
VoipMSNumber string VoipMSNumber string
VoipMSUsername string VoipMSUsername string
) )
// Build the ArcGIS authorization URL with PKCE // Build the ArcGIS authorization URL with PKCE
@ -93,6 +94,10 @@ func Parse() error {
if FilesDirectoryUser == "" { if FilesDirectoryUser == "" {
return fmt.Errorf("You must specify a non-empty FILES_DIRECTORY_USER") 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") ForwardEmailAPIToken = os.Getenv("FORWARDEMAIL_API_TOKEN")
if ForwardEmailAPIToken == "" { if ForwardEmailAPIToken == "" {
return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_API_TOKEN") return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_API_TOKEN")

View file

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/Gleipnir-Technology/nidus-sync/comms" "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"
"github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/db/models"
@ -129,19 +130,21 @@ func postQuick(w http.ResponseWriter, r *http.Request) {
return return
} }
log.Info().Int("len", len(images)).Msg("saved uploads") log.Info().Int("len", len(images)).Msg("saved uploads")
setters := make([]*models.PublicreportQuickImageSetter, 0) if len(images) > 0 {
for _, image := range images { setters := make([]*models.PublicreportQuickImageSetter, 0)
setters = append(setters, &models.PublicreportQuickImageSetter{ for _, image := range images {
ImageID: omit.From(int32(image.ID)), setters = append(setters, &models.PublicreportQuickImageSetter{
QuickID: omit.From(int32(quick.ID)), 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) tx.Commit(ctx)
http.Redirect(w, r, fmt.Sprintf("/quick-submit-complete?report=%s", u), http.StatusFound) 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 != "" { if email != "" {
comms.SendEmail(comms.EmailRequest{ comms.SendEmail(comms.EmailRequest{
From: "website@mosquitoes.online", From: config.ForwardEmailReportAddress,
To: email, To: email,
Subject: "test 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 != "" { 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) http.Redirect(w, r, fmt.Sprintf("/register-notifications-complete?report=%s", report_id), http.StatusFound)
} }
} }