39 lines
876 B
Go
39 lines
876 B
Go
package mail
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"git.umbach.dev/app-idea/mailer/modules/mailer"
|
|
"github.com/gofiber/fiber/v2"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type MailInput struct {
|
|
Key string `json:"k"`
|
|
Mail string `json:"m"`
|
|
TemplateId int `json:"t"`
|
|
LanguageId int `json:"l"`
|
|
BodyData *json.RawMessage `json:"d"`
|
|
}
|
|
|
|
func SendMail(c *fiber.Ctx) error {
|
|
var input MailInput
|
|
|
|
if err := c.BodyParser(&input); err != nil {
|
|
log.Infoln("bodyParser failed:", err)
|
|
return c.SendStatus(fiber.StatusUnauthorized)
|
|
}
|
|
|
|
var bodyData map[string]interface{}
|
|
|
|
if err := json.Unmarshal(*input.BodyData, &bodyData); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Infoln("input", input, bodyData)
|
|
|
|
mailer.NewMail([]string{"app@roese.dev"}, input.TemplateId, input.LanguageId, bodyData)
|
|
|
|
return c.SendStatus(fiber.StatusOK)
|
|
}
|