Files

45 lines
930 B
Go
Raw Permalink Normal View History

2020-10-24 23:38:14 +03:00
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
2020-10-24 23:38:14 +03:00
package cmd
import (
2025-06-10 14:35:12 +02:00
"context"
2020-10-24 23:38:14 +03:00
"fmt"
"code.gitea.io/gitea/modules/private"
2020-10-27 00:42:27 +08:00
"code.gitea.io/gitea/modules/setting"
2025-06-10 14:35:12 +02:00
"github.com/urfave/cli/v3"
2020-10-24 23:38:14 +03:00
)
2025-06-10 14:35:12 +02:00
func runSendMail(ctx context.Context, c *cli.Command) error {
2023-06-21 13:50:26 +08:00
setting.MustInstalled()
2020-10-27 00:42:27 +08:00
2020-10-24 23:38:14 +03:00
subject := c.String("title")
2026-02-28 20:23:20 +01:00
confirmSkipped := c.Bool("force")
2020-10-24 23:38:14 +03:00
body := c.String("content")
2026-02-28 20:23:20 +01:00
if !confirmSkipped {
2020-10-24 23:38:14 +03:00
if len(body) == 0 {
fmt.Print("warning: Content is empty")
}
fmt.Print("Proceed with sending email? [Y/n] ")
isConfirmed, err := confirm()
if err != nil {
return err
} else if !isConfirmed {
fmt.Println("The mail was not sent")
return nil
}
}
respText, extra := private.SendEmail(ctx, subject, body, nil)
if extra.HasError() {
return handleCliResponseExtra(extra)
2020-10-24 23:38:14 +03:00
}
_, _ = fmt.Printf("Sent %s email(s) to all users\n", respText.Text)
2020-10-24 23:38:14 +03:00
return nil
}