我正在嘗試通過標準庫SMTP包發(fā)送郵件,并且它在10分鐘內(nèi)什么都沒做,然后由于我無法理解的無用文件結(jié)尾錯誤而失敗。// excerpt from the calling function// --- snip ---if e := mailNotify(board, validPosts, ipMinusPort, delTime); e != nil { errorPage(w, tmpl, "Contact Administrator", "Email notification failed, please contact archive admin.") log.Println("ERROR: Failed to send notification email: " + e.Error())}// --- snip ---func mailNotify(board *config.Board, validPosts []int64, ip string, delTime time.Time) error { addresses := strings.Split(board.NotifyAddr, ",") if len(addresses) < 1 { return nil } msg := new(bytes.Buffer) type values struct { IP string Posts []int64 DelTime time.Time } t.ExecuteTemplate(msg, "post_reported", &values{ip, validPosts, delTime}) auth:= smtp.PlainAuth("", board.NotifyAddr, board.NotifyPass, strings.Split(board.SMTPServer, ":")[0]) return smtp.SendMail(board.SMTPServer, auth, board.FromEmail, addresses, msg.Bytes())}記錄的確切消息是:2012/07/25 22:57:58錯誤:無法發(fā)送通知電子郵件:EOF我已經(jīng)log.Printf調(diào)試了此功能,并驗證了此時發(fā)送的值是否有效。該電子郵件地址是gmail.com上的真實地址,并且密碼正確,并且board.SMTPServer為smtp.googlemail.com:465。我嘗試將msg.Bytes()的結(jié)果存儲在一個單獨的變量中,并采用長度來確保它正在生成要發(fā)送的字節(jié)數(shù)組,并且長度的確不為零。我猜測EOF正在從標準庫中比SendMail函數(shù)本身更深的地方冒出來,但是我不知道它在哪里阻塞,我不知道該怎么做。
1 回答

慕容3067478
TA貢獻1773條經(jīng)驗 獲得超3個贊
Gmail的端口465用于通過TLS進行連接,但是SendMail希望使用簡單的舊TCP。嘗試改為連接到端口587??捎脮r,SendMail將自動升級到TLS(在本例中就是這種情況)。
- 1 回答
- 0 關(guān)注
- 649 瀏覽
添加回答
舉報
0/150
提交
取消