標準ライブラリの SMTP パッケージを介してメールを送信しようとしていますが、正確に 10 分間何もせず、役に立たない End of File エラーで失敗し、意味がわかりません。
// 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 関数自体よりも標準ライブラリのどこか深いところから泡立っていると思いますが、どこで窒息しているのかわかりません。