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.

mailer.go 1003B

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