This commit is contained in:
xing 2023-07-11 14:54:17 +08:00
parent 5a4d808f89
commit 395280a363
3 changed files with 18 additions and 6 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@
rss.iml
rss
fetchdapenti
/run.sh
/sendmail

View File

@ -88,6 +88,10 @@ func fetch(u string) (r rss2.Item) {
var hadSend = safety.NewMap[string, struct{}]()
func downAndSendMail(doc *goquery.Document, title string) {
if err := mail.CheckEnv(); err != nil {
log.Println("err", err)
return
}
type m struct {
tit string
content string

View File

@ -7,23 +7,29 @@ import (
"os/exec"
)
func SendMail(subject string, content string, files ...string) error {
cm := os.Getenv("mail_cmd_path")
var cm, subjectParam, contentParam, fileParam string
func CheckEnv() error {
cm = os.Getenv("mail_cmd_path")
if cm == "" {
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 == "" {
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 == "" {
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 == "" {
return errors.New("file empty")
}
return nil
}
func SendMail(subject string, content string, files ...string) error {
v := []string{subjectParam, subject, contentParam, content}
for _, f := range files {
if f != "" {