From 196cd88b1c7c44a337ca12f6a804f1bb7fa83c4a Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 14 Mar 2023 17:11:04 +0100 Subject: [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 --- internal/email/reset.go | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'internal/email/reset.go') diff --git a/internal/email/reset.go b/internal/email/reset.go index 0b950c1c9..cb1da9fee 100644 --- a/internal/email/reset.go +++ b/internal/email/reset.go @@ -20,6 +20,8 @@ package email import ( "bytes" "net/smtp" + + "github.com/superseriousbusiness/gotosocial/internal/gtserror" ) const ( @@ -27,6 +29,19 @@ const ( resetSubject = "GoToSocial Password Reset" ) +// ResetData represents data passed into the reset email address template. +type ResetData struct { + // Username to be addressed. + Username string + // URL of the instance to present to the receiver. + InstanceURL string + // Name of the instance to present to the receiver. + InstanceName string + // Link to present to the receiver to click on and begin the reset process. + // 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 { @@ -38,18 +53,10 @@ func (s *sender) SendResetEmail(toAddress string, data ResetData) error { 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. - Username string - // URL of the instance to present to the receiver. - InstanceURL string - // Name of the instance to present to the receiver. - InstanceName string - // Link to present to the receiver to click on and begin the reset process. - // Should be a full link with protocol eg., https://example.org/reset_password?token=some-reset-password-token - ResetLink string + if err := smtp.SendMail(s.hostAddress, s.auth, s.from, []string{toAddress}, msg); err != nil { + return gtserror.SetType(err, gtserror.TypeSMTP) + } + + return nil } -- cgit v1.2.3