英文:
golang: Read multiline error response from smtp.SendMail
问题
我正在使用这段代码:
err := smtp.SendMail(
smtpHostPort,
auth,
sender,
[]string{recipient},
[]byte(message),
)
if err != nil {
log.Printf("sendSmtp: failure: %q", strings.Split(err.Error(), "\n"))
}
然而,多行错误响应似乎被截断了:
2013/02/06 11:54:41 sendSmtp: failure: ["530 5.5.1 Authentication Required. Learn more at"]
如何获取完整的多行错误响应?
英文:
I am using this code:
err := smtp.SendMail(
smtpHostPort,
auth,
sender,
[]string{recipient},
[]byte(message),
)
if err != nil {
log.Printf("sendSmtp: failure: %q", strings.Split(err.Error(), "\n"))
}
However the multiline error response seems truncated:
2013/02/06 11:54:41 sendSmtp: failure: ["530 5.5.1 Authentication Required. Learn more at"]
How can I get the full multiline error response?
答案1
得分: 1
这个问题已经被修复:
https://code.google.com/p/go/issues/detail?id=5700
答案2
得分: 0
错误不是多行字符串。
package main
import (
"errors"
"log"
"strings"
)
func main() {
err := errors.New("530 5.5.1 需要身份验证。了解更多信息,请访问")
log.Printf("sendSmtp: 失败:%q", strings.Split(err.Error(), "\n"))
err = errors.New("530 5.5.1 需要身份验证。了解更多信息,请访问\nstackoverflow.com")
log.Printf("sendSmtp: 失败:%q", strings.Split(err.Error(), "\n"))
}
输出:
2013/02/06 13:30:19 sendSmtp: 失败:["530 5.5.1 需要身份验证。了解更多信息,请访问"]
2013/02/06 13:30:19 sendSmtp: 失败:["530 5.5.1 需要身份验证。了解更多信息,请访问" "stackoverflow.com"]
英文:
The error is not a multi-line string.
package main
import (
"errors"
"log"
"strings"
)
func main() {
err := errors.New("530 5.5.1 Authentication Required. Learn more at")
log.Printf("sendSmtp: failure: %q", strings.Split(err.Error(), "\n"))
err = errors.New("530 5.5.1 Authentication Required. Learn more at\nstackoverflow.com")
log.Printf("sendSmtp: failure: %q", strings.Split(err.Error(), "\n"))
}
Output:
2013/02/06 13:30:19 sendSmtp: failure: ["530 5.5.1 Authentication Required. Learn more at"]
2013/02/06 13:30:19 sendSmtp: failure: ["530 5.5.1 Authentication Required. Learn more at" "stackoverflow.com"]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论