Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
smtp.SendMail在10分钟后使用EOF失败_Smtp_Go - Fatal编程技术网

smtp.SendMail在10分钟后使用EOF失败

smtp.SendMail在10分钟后使用EOF失败,smtp,go,Smtp,Go,我试图通过标准库SMTP包发送邮件,但它在整整10分钟内什么也不做,然后失败,出现了一个我无法理解的无用的文件结束错误 // excerpt from the calling function // --- snip --- if e := mailNotify(board, validPosts, ipMinusPort, delTime); e != nil { errorPage(w, tmpl, "Contact Administrator", "Email no

我试图通过标准库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())
}
//从调用函数中摘录
//---剪---
如果e:=邮件通知(董事会、有效邮件、ipMinusPort、delTime);e!=零{
错误页面(w,tmpl,“联系管理员”,
“电子邮件通知失败,请与存档管理员联系。”)
log.Println(“错误:无法发送通知电子邮件:”+e.ERROR())
}
//---剪---
func mailNotify(board*config.board,validPosts[]int64,
ip字符串,delTime.time)错误{
地址:=strings.Split(board.NotifyAddr,“,”)
如果len(地址)<1{
归零
}
msg:=新建(字节.缓冲区)
类型值结构{
IP字符串
发布[]int64
时间,时间,时间
}
t、 ExecuteTemplate(msg,“post_reported”&值{ip,validPosts,delTime})
auth:=smtp.PlainAuth(“”,board.NotifyAddr,board.NotifyPass,
strings.Split(board.SMTPServer,“:”[0])
返回smtp.SendMail(board.SMTPServer,auth,
board.FromEmail、地址、msg.Bytes()
}
记录的确切消息是:

2012/07/25 22:57:58错误:无法发送通知电子邮件:EOF


我已
log.Printf
调试了此函数,并验证了此时发送的值是否有效。电子邮件地址是gmail.com上的真实地址,密码正确,
board.SMTPServer
smtp.googlemail.com:465
。我已经尝试将msg.Bytes()的结果存储在一个单独的变量中,并获取长度以确保它正在生成一个要发送的字节数组,并且长度确实不是零。我猜EOF是从标准库中比SendMail函数本身更深的地方冒出来的,但我不知道它在哪里阻塞了,我不知道我做了什么使它不安。

Gmail的465端口用于通过TLS进行连接,但SendMail希望使用普通的旧TCP。请尝试连接到端口587。SendMail在可用时会自动升级到TLS(在本例中就是这样)。

这里没有什么真正需要做的。能否为库启用调试日志记录?有网络流量吗?我正要把头撞到墙上。错误中没有描述。它说的是“EOF”。你的解决方案非常有效。