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 1019B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cmd
  5. import (
  6. "fmt"
  7. "net/http"
  8. "code.gitea.io/gitea/modules/private"
  9. "code.gitea.io/gitea/modules/setting"
  10. "github.com/urfave/cli"
  11. )
  12. func runSendMail(c *cli.Context) error {
  13. setting.NewContext()
  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. status, message := private.SendEmail(subject, body, nil)
  34. if status != http.StatusOK {
  35. fmt.Printf("error: %s\n", message)
  36. return nil
  37. }
  38. fmt.Printf("Success: %s\n", message)
  39. return nil
  40. }