我有一个 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 := "foo@gmail.com" 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 关注
- 71 浏览
添加回答
举报
0/150
提交
取消