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

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 に答える