3
我使用go的net/smtp
發送電子郵件,它對一些電子郵件正常工作,但不適用於其他電子郵件。我得到一個554 5.5.1 Error: no valid recipients
,但我很確定我給了正確的郵件地址。調試SMTP連接
(最終目標是讓所有郵件收件人net/smtp
的工作。所以答案上亦歡迎)
如何調試發生了什麼事情的背景是什麼?什麼命令發送到SMTP服務器和從SMTP服務器發送?我想重播命令行(telnet)中的命令以瞭解更多關於錯誤的信息。
這是我使用的代碼(from the go-wiki):
package main
import (
"bytes"
"log"
"net/smtp"
)
func main() {
// Connect to the remote SMTP server.
c, err := smtp.Dial("mail.example.com:25")
if err != nil {
log.Fatal(err)
}
// Set the sender and recipient.
c.Mail("[email protected]")
c.Rcpt("[email protected]")
// Send the email body.
wc, err := c.Data()
if err != nil {
log.Fatal(err)
}
defer wc.Close()
buf := bytes.NewBufferString("This is the email body.")
if _, err = buf.WriteTo(wc); err != nil {
log.Fatal(err)
}
}
我知道這是一個非常模糊的問題,但任何幫助深表感謝。
您是否可以將收件人複製到您可以發佈的內容,以便重現此行爲? – nemo
@nemo我已經做了一些進一步的調試,看起來好像其他主機需要非本地主機'EHLO'命令。所以'client.Hello(myhost)'幫了個忙。我應該自問或者完全刪除它嗎? – topskip
絕對自我回答!對於同一個人的任何人來說,這都是有價值的信息 – nemo