我正在尝试通过标准库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())
}
Run Code Online (Sandbox Code Playgroud)
记录的确切消息是:
2012/07/25 22:57:58错误:无法发送通知电子邮件:EOF
我已log.Printf调试此函数并验证此时发送的值是否有效.电子邮件地址是gmail.com上的真实地址,密码正确,而且board.SMTPServer是smtp.googlemail.com:465.我已经尝试将msg.Bytes()的结果存储在一个单独的变量中并获取长度以确保它生成一个要发送的字节数组,并且长度确实非零.我猜EOF正在从标准库中比在SendMail函数本身更深的地方冒泡,但我不知道它在哪里窒息而且我不知道我做了什么来扰乱它.
| 归档时间: |
|
| 查看次数: |
4490 次 |
| 最近记录: |