diff --git a/bbclearn/bbc.go b/bbclearn/bbc.go index 58e9927..164a285 100644 --- a/bbclearn/bbc.go +++ b/bbclearn/bbc.go @@ -122,7 +122,11 @@ func downAndSendMail(doc *goquery.Document, title string) { if len(mm.f) < 1 { return } - mail.SendMail(mm.tit, mm.content, mm.f...) + err = mail.SendMail(mm.tit, mm.content, mm.f...) + if err != nil { + log.Println("err", err) + return + } hadSend.Store(mm.tit, struct{}{}) for _, s := range mm.f { err := os.Remove(s) diff --git a/mail/mail.go b/mail/mail.go index a04feea..202ba50 100644 --- a/mail/mail.go +++ b/mail/mail.go @@ -1,27 +1,28 @@ package mail import ( + "errors" "log" "os" "os/exec" ) -func SendMail(subject string, content string, files ...string) { +func SendMail(subject string, content string, files ...string) error { cm := os.Getenv("mail_cmd_path") if cm == "" { - return + return errors.New("cmd can't empty") } subjectParam := os.Getenv("mail_cmd_subject_param_name") if subjectParam == "" { - return + return errors.New("title param name empty") } contentParam := os.Getenv("mail_cmd_content_param_name") if contentParam == "" { - return + return errors.New("content param name emtpy") } fileParam := os.Getenv("mail_cmd_file_param_name") if fileParam == "" { - return + return errors.New("file empty") } v := []string{subjectParam, subject, contentParam, content} for _, f := range files { @@ -31,6 +32,15 @@ func SendMail(subject string, content string, files ...string) { } cmd := exec.Command(cm, v...) + file, err := os.OpenFile("run.sh", os.O_CREATE|os.O_APPEND, 0755) + if err != nil { + return err + } + _, err = file.WriteString(cmd.String()) + if err != nil { + return err + } output, err := cmd.CombinedOutput() - log.Println(string(output), err) + log.Println(string(output)) + return err }