BREAKING CHANGE: The original Go module name was `github.com/ArtalkJS/Artalk`, which has now been modified to `github.com/artalkjs/artalk/v2` (all lowercase). This change may affect the CI pipeline or other areas if you are compiling the Artalk server and have specified the fixed Go module name. Regarding the original `-ldflags -X github.com/ArtalkJS/Artalk/internal/config.Version` and `CommitHash` definitions, please remove them, as they are now obsolete. The `Version` has been hardcoded into the Go code, and the `CommitHash` is now read from the Go build info via runtime/debug’s vcs.revision value. This change only affects the server developers and does not impact the frontend UI client.
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/artalkjs/artalk/v2/internal/core"
|
|
"github.com/artalkjs/artalk/v2/internal/log"
|
|
"github.com/artalkjs/artalk/v2/server/common"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type ParamsEmailSend struct {
|
|
Subject string `json:"subject" validate:"required"` // The subject of email
|
|
Body string `json:"body" validate:"required"` // The body of email
|
|
ToAddr string `json:"to_addr" validate:"required"` // The email address of the receiver
|
|
}
|
|
|
|
// @Id SendEmail
|
|
// @Summary Send Email
|
|
// @Description Send an email to test the email sender
|
|
// @Tags System
|
|
// @Security ApiKeyAuth
|
|
// @Param email body ParamsEmailSend true "The email data"
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} Map{}
|
|
// @Failure 403 {object} Map{msg=string}
|
|
// @Failure 500 {object} Map{}
|
|
// @Router /send_email [post]
|
|
func EmailSend(app *core.App, router fiber.Router) {
|
|
router.Post("/send_email", common.AdminGuard(app, func(c *fiber.Ctx) error {
|
|
var p ParamsEmailSend
|
|
if isOK, resp := common.ParamsDecode(c, &p); !isOK {
|
|
return resp
|
|
}
|
|
|
|
emailService, err := core.AppService[*core.EmailService](app)
|
|
if err != nil {
|
|
log.Error("[EmailService] err: ", err)
|
|
return common.RespError(c, 500, "EmailService err: "+err.Error())
|
|
}
|
|
emailService.AsyncSendTo(p.Subject, p.Body, p.ToAddr)
|
|
|
|
return common.RespSuccess(c)
|
|
}))
|
|
}
|