You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail.go 927B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package private
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/modules/setting"
  7. )
  8. // Email structure holds a data for sending general emails
  9. type Email struct {
  10. Subject string
  11. Message string
  12. To []string
  13. }
  14. // SendEmail calls the internal SendEmail function
  15. // It accepts a list of usernames.
  16. // If DB contains these users it will send the email to them.
  17. // If to list == nil, it's supposed to send emails to every user present in DB
  18. func SendEmail(ctx context.Context, subject, message string, to []string) (string, ResponseExtra) {
  19. reqURL := setting.LocalURL + "api/internal/mail/send"
  20. req := newInternalRequest(ctx, reqURL, "POST", Email{
  21. Subject: subject,
  22. Message: message,
  23. To: to,
  24. })
  25. resp, extra := requestJSONResp(req, &responseText{})
  26. if extra.HasError() {
  27. return "", extra
  28. }
  29. return resp.Text, extra
  30. }