英文:
smtp.SendMail fails after 10 minutes with EOF
问题
我正在尝试通过标准库SMTP包发送邮件,但它在10分钟后什么都不做,然后失败并显示一个无用的文件结束错误,我无法理解。
// 调用函数的摘录
// --- 剪辑 ---
如果e:= mailNotify(board,validPosts,ipMinusPort,delTime); e!= nil {
errorPage(w,tmpl,“联系管理员”,
“电子邮件通知失败,请联系存档管理员。”)
log.Println(“错误:无法发送通知电子邮件:”+ e.Error())
}
// --- 剪辑 ---
func mailNotify(board * config.Board,validPosts [] int64,
ip string,delTime time.Time)错误{
addresses:= strings.Split(board.NotifyAddr,“,”)
if len(addresses)<1 {
返回零
}
msg:= new(bytes.Buffer)
类型值结构{
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])
返回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函数本身更深入的标准库中冒出来的,但我不知道它在哪里出错,也不知道我做了什么让它不满意。
英文:
I'm trying to send mail via the standard library SMTP package and it does nothing for exactly 10 minutes and then fails with an unhelpful End of File error I can't make sense of.
// 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())
}
The exact message that gets logged is:
> 2012/07/25 22:57:58 ERROR: Failed to send notification email: EOF
I've log.Printf
debugged this function and verified the values being sent at this point are valid. The email address is a real address on gmail.com and the password is correct, and board.SMTPServer
is smtp.googlemail.com:465
. I've tried storing the result of msg.Bytes() in a separate variable and taking the length to be sure that it was producing an byte array to send, and the length is indeed non-zero. I'm guessing the EOF is bubbling up from somwhere deeper in the standard library than the SendMail function itself, but I have no idea where it's choking and I don't know what I did to upset it.
答案1
得分: 32
Gmail的端口465用于通过TLS连接,但SendMail期望使用普通的TCP。尝试连接到端口587。当TLS可用时,SendMail会自动升级(在这种情况下是可用的)。
英文:
Gmail's port 465 is for connecting via TLS, but SendMail expects plain old TCP. Try connecting to port 587 instead. SendMail will upgrade to TLS automatically when it's available (which it is in this case).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论