From 21f872d77c05d48d351b9986ab038af4397ec086 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 11 Jul 2023 12:12:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bbclearn/bbc.go | 6 +++++- mail/mail.go | 22 ++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) 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 }