mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Allow admins to send test emails (#1620)
* [feature] Allow admins to send test emails * implement unwrap on new error type * add + use gtserror types * GoToSocial Email Test -> GoToSocial Test Email * add + use getInstance db call * removed unused "unknown" error type
This commit is contained in:
@ -21,8 +21,7 @@ import (
|
||||
"bytes"
|
||||
"net/smtp"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -30,21 +29,6 @@ const (
|
||||
confirmSubject = "GoToSocial Email Confirmation"
|
||||
)
|
||||
|
||||
func (s *sender) SendConfirmEmail(toAddress string, data ConfirmData) error {
|
||||
buf := &bytes.Buffer{}
|
||||
if err := s.template.ExecuteTemplate(buf, confirmTemplate, data); err != nil {
|
||||
return err
|
||||
}
|
||||
confirmBody := buf.String()
|
||||
|
||||
msg, err := assembleMessage(confirmSubject, confirmBody, toAddress, s.from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Trace(nil, s.hostAddress+"\n"+config.GetSMTPUsername()+":password"+"\n"+s.from+"\n"+toAddress+"\n\n"+string(msg)+"\n")
|
||||
return smtp.SendMail(s.hostAddress, s.auth, s.from, []string{toAddress}, msg)
|
||||
}
|
||||
|
||||
// ConfirmData represents data passed into the confirm email address template.
|
||||
type ConfirmData struct {
|
||||
// Username to be addressed.
|
||||
@ -57,3 +41,22 @@ type ConfirmData struct {
|
||||
// Should be a full link with protocol eg., https://example.org/confirm_email?token=some-long-token
|
||||
ConfirmLink string
|
||||
}
|
||||
|
||||
func (s *sender) SendConfirmEmail(toAddress string, data ConfirmData) error {
|
||||
buf := &bytes.Buffer{}
|
||||
if err := s.template.ExecuteTemplate(buf, confirmTemplate, data); err != nil {
|
||||
return err
|
||||
}
|
||||
confirmBody := buf.String()
|
||||
|
||||
msg, err := assembleMessage(confirmSubject, confirmBody, toAddress, s.from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := smtp.SendMail(s.hostAddress, s.auth, s.from, []string{toAddress}, msg); err != nil {
|
||||
return gtserror.SetType(err, gtserror.TypeSMTP)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user