完善
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 {
|
if len(mm.f) < 1 {
|
||||||
return
|
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{}{})
|
hadSend.Store(mm.tit, struct{}{})
|
||||||
for _, s := range mm.f {
|
for _, s := range mm.f {
|
||||||
err := os.Remove(s)
|
err := os.Remove(s)
|
||||||
|
|
22
mail/mail.go
22
mail/mail.go
|
@ -1,27 +1,28 @@
|
||||||
package mail
|
package mail
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"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")
|
cm := os.Getenv("mail_cmd_path")
|
||||||
if cm == "" {
|
if cm == "" {
|
||||||
return
|
return errors.New("cmd can't empty")
|
||||||
}
|
}
|
||||||
subjectParam := os.Getenv("mail_cmd_subject_param_name")
|
subjectParam := os.Getenv("mail_cmd_subject_param_name")
|
||||||
if subjectParam == "" {
|
if subjectParam == "" {
|
||||||
return
|
return errors.New("title param name empty")
|
||||||
}
|
}
|
||||||
contentParam := os.Getenv("mail_cmd_content_param_name")
|
contentParam := os.Getenv("mail_cmd_content_param_name")
|
||||||
if contentParam == "" {
|
if contentParam == "" {
|
||||||
return
|
return errors.New("content param name emtpy")
|
||||||
}
|
}
|
||||||
fileParam := os.Getenv("mail_cmd_file_param_name")
|
fileParam := os.Getenv("mail_cmd_file_param_name")
|
||||||
if fileParam == "" {
|
if fileParam == "" {
|
||||||
return
|
return errors.New("file empty")
|
||||||
}
|
}
|
||||||
v := []string{subjectParam, subject, contentParam, content}
|
v := []string{subjectParam, subject, contentParam, content}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
|
@ -31,6 +32,15 @@ func SendMail(subject string, content string, files ...string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command(cm, v...)
|
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()
|
output, err := cmd.CombinedOutput()
|
||||||
log.Println(string(output), err)
|
log.Println(string(output))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user