package mail import ( "errors" "log" "os" "os/exec" ) 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") if subjectParam == "" { return errors.New("title param name empty") } 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") 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 != "" { v = append(v, fileParam, f) } } cmd := exec.Command(cm, v...) output, err := cmd.CombinedOutput() log.Println(string(output)) return err }