我正在尝试通过标准库 SMTP 包发送邮件,它在整整 10 分钟内什么都不做,然后失败并出现我无法理解的无用的文件结束错误。
// 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 错误:无法发送通知电子邮件:EOF
我已经log.Printf
调试了这个函数并验证了此时发送的值是有效的。电子邮件地址是 gmail.com 上的真实地址,密码正确,并且board.SMTPServer
是smtp.googlemail.com:465
. 我尝试将 msg.Bytes() 的结果存储在一个单独的变量中,并获取长度以确保它正在生成要发送的字节数组,并且长度确实非零。我猜 EOF 是从标准库中比 SendMail 函数本身更深的地方冒出来的,但我不知道它在哪里窒息,我不知道我做了什么来扰乱它。