gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "context"
  6. "fmt"
  7. "code.gitea.io/gitea/modules/private"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/urfave/cli/v3"
  10. )
  11. func runSendMail(ctx context.Context, c *cli.Command) error {
  12. setting.MustInstalled()
  13. subject := c.String("title")
  14. confirmSkiped := c.Bool("force")
  15. body := c.String("content")
  16. if !confirmSkiped {
  17. if len(body) == 0 {
  18. fmt.Print("warning: Content is empty")
  19. }
  20. fmt.Print("Proceed with sending email? [Y/n] ")
  21. isConfirmed, err := confirm()
  22. if err != nil {
  23. return err
  24. } else if !isConfirmed {
  25. fmt.Println("The mail was not sent")
  26. return nil
  27. }
  28. }
  29. respText, extra := private.SendEmail(ctx, subject, body, nil)
  30. if extra.HasError() {
  31. return handleCliResponseExtra(extra)
  32. }
  33. _, _ = fmt.Printf("Sent %s email(s) to all users\n", respText.Text)
  34. return nil
  35. }