我有一個 Go 程序,可以向我發送郵件。package mainimport ( "log" "net/smtp" "os")func main() { send(os.Args[2] + " program completed.", os.Args[1], os.Args[2], os.Args[3])}func send(body string, to string, s string, date string) { from := "[email protected]" pass := "bar" msg := "From: " + from + "\n" + "To: " + to + "\n" + "Subject: "+ s + " main\n\n" + body + "\n" + date err := smtp.SendMail("smtp.gmail.com:587", smtp.PlainAuth("", from, pass, "smtp.gmail.com"), from, []string{to}, []byte(msg)) if err != nil { log.Printf("smtp error: %s", err) return } log.Print("sent, visit mail address: "+to)}還有一個bash腳本,它使用郵件列表運行它,以備將來準備,Do things.......filename='list'while read line; do# reading each line of listecho "$(date '+%d-%m-%Y-%T') Mail sent to address : $line" >> ${now}-log.log./mailsend ${line} foo ${date}done < $filenameDo final things .....如您所見,有一些簡單的日志嘗試,以查看程序是否運行良好。并且沒有錯誤。當我手動觸發程序時,它可以完美地工作,但是從由cronjob觸發的bash腳本中,它不起作用。有什么建議嗎?edit1:變量是實心的。曼努埃爾觸發器按預期工作。當由 cron 觸發時,我不會收到郵件。
- 1 回答
- 0 關注
- 85 瀏覽
添加回答
舉報
0/150
提交
取消