Skip to content

Commit 22907f6

Browse files
Merge pull request #35 from stackroost/dev
feat(cli): add test-email command to check mail capability
2 parents b305355 + 171901a commit 22907f6

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

cmd/email/test_email.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package email
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
8+
"github.com/spf13/cobra"
9+
"stackroost/internal/logger"
10+
)
11+
12+
13+
var TestEmailCmd = &cobra.Command{
14+
Use: "test-email",
15+
Short: "Check if email capability is available on this system (mail/sendmail/msmtp)",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
mailers := []string{"mail", "sendmail", "msmtp"}
18+
found := false
19+
20+
for _, bin := range mailers {
21+
_, err := exec.LookPath(bin)
22+
if err == nil {
23+
logger.Success(fmt.Sprintf("Mailer available: %s", bin))
24+
found = true
25+
}
26+
}
27+
28+
if !found {
29+
logger.Warn("No mail sending utilities found (mail/sendmail/msmtp)")
30+
logger.Info("You can install one, e.g., `sudo apt install mailutils` or `sendmail`")
31+
os.Exit(1)
32+
}
33+
34+
logger.Info("Email sending capability appears to be available")
35+
},
36+
}
37+
38+
func init() {
39+
TestEmailCmd.Flags().String("to", "", "Recipient email address")
40+
TestEmailCmd.MarkFlagRequired("to")
41+
}

cmd/root.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"stackroost/cmd/ssl"
1313
"stackroost/cmd/logs"
14+
"stackroost/cmd/email"
1415
)
1516

1617
var rootCmd = &cobra.Command{
@@ -211,7 +212,8 @@ func init() {
211212
createDomainCmd.Flags().Bool("ssl", false, "Enable Let's Encrypt SSL (Apache/Nginx only)")
212213
createDomainCmd.MarkFlagRequired("name")
213214
rootCmd.AddCommand(ssl.CheckSSLExpiryCmd)
214-
rootCmd.AddCommand(logs.AnalyzeTrafficCmd)
215+
rootCmd.AddCommand(logs.AnalyzeTrafficCmd)
216+
rootCmd.AddCommand(email.TestEmailCmd)
215217
}
216218

217219
func Execute() {

0 commit comments

Comments
 (0)