Files
Atay-Makhzan/cmd/mailer.go
T

45 lines
928 B
Go
Raw 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")
confirmSkiped := c.Bool("force")
body := c.String("content")
if !confirmSkiped {
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
}