mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-30 08:22:24 -05: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:
parent
d5529d6c9f
commit
196cd88b1c
17 changed files with 460 additions and 83 deletions
|
|
@ -20,6 +20,8 @@ package email
|
|||
import (
|
||||
"bytes"
|
||||
"net/smtp"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -27,20 +29,6 @@ const (
|
|||
resetSubject = "GoToSocial Password Reset"
|
||||
)
|
||||
|
||||
func (s *sender) SendResetEmail(toAddress string, data ResetData) error {
|
||||
buf := &bytes.Buffer{}
|
||||
if err := s.template.ExecuteTemplate(buf, resetTemplate, data); err != nil {
|
||||
return err
|
||||
}
|
||||
resetBody := buf.String()
|
||||
|
||||
msg, err := assembleMessage(resetSubject, resetBody, toAddress, s.from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return smtp.SendMail(s.hostAddress, s.auth, s.from, []string{toAddress}, msg)
|
||||
}
|
||||
|
||||
// ResetData represents data passed into the reset email address template.
|
||||
type ResetData struct {
|
||||
// Username to be addressed.
|
||||
|
|
@ -53,3 +41,22 @@ type ResetData struct {
|
|||
// Should be a full link with protocol eg., https://example.org/reset_password?token=some-reset-password-token
|
||||
ResetLink string
|
||||
}
|
||||
|
||||
func (s *sender) SendResetEmail(toAddress string, data ResetData) error {
|
||||
buf := &bytes.Buffer{}
|
||||
if err := s.template.ExecuteTemplate(buf, resetTemplate, data); err != nil {
|
||||
return err
|
||||
}
|
||||
resetBody := buf.String()
|
||||
|
||||
msg, err := assembleMessage(resetSubject, resetBody, 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue