完善
This commit is contained in:
parent
f04c9d1679
commit
21f872d77c
|
@ -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)
|
||||
|
|
24
mail/mail.go
24
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...)
|
||||
output, err := cmd.CombinedOutput()
|
||||
log.Println(string(output), err)
|
||||
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))
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user