File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
1111 "strings"
1212 "stackroost/cmd/ssl"
1313 "stackroost/cmd/logs"
14+ "stackroost/cmd/email"
1415)
1516
1617var 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
217219func Execute () {
You can’t perform that action at this time.
0 commit comments