Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions cmd/email/test_email.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package email

import (
"fmt"
"os"
"os/exec"

"github.com/spf13/cobra"
"stackroost/internal/logger"
)


var TestEmailCmd = &cobra.Command{
Use: "test-email",
Short: "Check if email capability is available on this system (mail/sendmail/msmtp)",
Run: func(cmd *cobra.Command, args []string) {
mailers := []string{"mail", "sendmail", "msmtp"}
found := false

for _, bin := range mailers {
_, err := exec.LookPath(bin)
if err == nil {
logger.Success(fmt.Sprintf("Mailer available: %s", bin))
found = true
}
}

if !found {
logger.Warn("No mail sending utilities found (mail/sendmail/msmtp)")
logger.Info("You can install one, e.g., `sudo apt install mailutils` or `sendmail`")
os.Exit(1)
}

logger.Info("Email sending capability appears to be available")
},
}

func init() {
TestEmailCmd.Flags().String("to", "", "Recipient email address")
TestEmailCmd.MarkFlagRequired("to")
}
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"stackroost/cmd/ssl"
"stackroost/cmd/logs"
"stackroost/cmd/email"
)

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -211,7 +212,8 @@ func init() {
createDomainCmd.Flags().Bool("ssl", false, "Enable Let's Encrypt SSL (Apache/Nginx only)")
createDomainCmd.MarkFlagRequired("name")
rootCmd.AddCommand(ssl.CheckSSLExpiryCmd)
rootCmd.AddCommand(logs.AnalyzeTrafficCmd)
rootCmd.AddCommand(logs.AnalyzeTrafficCmd)
rootCmd.AddCommand(email.TestEmailCmd)
}

func Execute() {
Expand Down