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 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. ctx, cancel := installSignals()
  14. defer cancel()
  15. setting.LoadFromExisting()
  16. if err := argsSet(c, "title"); err != nil {
  17. return err
  18. }
  19. subject := c.String("title")
  20. confirmSkiped := c.Bool("force")
  21. body := c.String("content")
  22. if !confirmSkiped {
  23. if len(body) == 0 {
  24. fmt.Print("warning: Content is empty")
  25. }
  26. fmt.Print("Proceed with sending email? [Y/n] ")
  27. isConfirmed, err := confirm()
  28. if err != nil {
  29. return err
  30. } else if !isConfirmed {
  31. fmt.Println("The mail was not sent")
  32. return nil
  33. }
  34. }
  35. status, message := private.SendEmail(ctx, subject, body, nil)
  36. if status != http.StatusOK {
  37. fmt.Printf("error: %s\n", message)
  38. return nil
  39. }
  40. fmt.Printf("Success: %s\n", message)
  41. return nil
  42. }