2022-05-01 17:57:30 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/smtp2go-oss/smtp2go-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
type sendMessageRequest struct {
|
|
|
|
Title string `json:"title"`
|
|
|
|
Body string `json:"body"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) contactHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
smr := &sendMessageRequest{}
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(smr); err != nil {
|
2022-05-21 14:00:21 +00:00
|
|
|
a.errorResponse(w, r, 500, err)
|
2022-05-01 17:57:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := &smtp2go.Email{
|
|
|
|
From: "🤖 Apollo API <robot@apollonotifications.com>",
|
|
|
|
To: []string{"ultrasurvey@apolloapp.io"},
|
|
|
|
Subject: smr.Title,
|
|
|
|
TextBody: smr.Body,
|
|
|
|
}
|
|
|
|
|
2022-05-07 16:37:21 +00:00
|
|
|
if _, err := smtp2go.Send(msg); err != nil {
|
2022-05-21 14:00:21 +00:00
|
|
|
a.errorResponse(w, r, 500, err)
|
2022-05-01 17:57:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
}
|