douren2395
2013-02-06 17:19
浏览 79
已采纳

golang:从smtp.SendMail读取多行错误响应

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

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?

图片转代码服务由CSDN问答提供 功能建议

我正在使用以下代码:

  err:= smtp  .SendMail(
 smtpHostPort,
 auth,
发件人,
 [] string {收件人},
 [] byte(消息),
)
if err!= nil {
 log.Printf(“  sendSmtp:失败:%q“,strings.Split(err.Error(),” 
“))
} 
   
 
 

不过,多行错误响应似乎 截断:

  2013/02/06 11:54:41 sendSmtp:失败:[“ 530 5.5.1要求身份验证。有关详细信息,”“] 
    
 
 

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

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxinpa3101 2014-04-04 17:55
    已采纳

    For the records, this bug has been fixed:

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

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duannan4486 2013-02-06 18:28

    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(), "
    "))
        err = errors.New("530 5.5.1 Authentication Required. Learn more at
    stackoverflow.com")
        log.Printf("sendSmtp: failure: %q", strings.Split(err.Error(), "
    "))
    }
    

    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"]
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题