2013-02-06 2 views
0
에서 여러 오류 응답을 읽고 나는이 코드를 사용하고

: 여러 줄 오류 응답이 잘릴 것 같다 그러나golang : 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"] 

을 ?

답변

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

그래서 보인다 오류 문자열을 반환했습니다. 함수에서 여러 줄 오류를 얻는 것이 불가능합니까? – Xeoncross

+0

원본에서 추적 할 수있는 한 smtp.SendMail은 결국 textproto.ReadResponse를 호출하여 다중 행 응답을 읽습니다. smtp.SendMail : http://golang.org/src/pkg/net/smtp/smtp. http://golang.org/src/pkg/net/textproto/reader.go ReadResponse 양식의 여러 줄 응답을 읽어 // : // // \t 코드 textproto.ReadResponse 이동 - 메시지 행 1 // \t 코드 메시지 행 2 // \t ... // \t 코드 메시지 행 n 버그 일 수 있으십니까? – Everton