0

我正在使用这段代码:

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"]

如何获得完整的多行错误响应?

4

2 回答 2

1

对于记录,此错误已修复:

https://code.google.com/p/go/issues/detail?id=5700

于 2014-04-04T17:55:32.220 回答
0

错误不是多行字符串。

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"))
}

输出:

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"]
于 2013-02-06T18:28:15.473 回答