我有下面的 go 程序,它會發送電子郵件。憑證是正確的。我什至用curl測試了它們,我發現連接是成功的。請注意,tls 不是必需的。
package main import ( "fmt" "log" "net/smtp" ) const ( username = "[email protected]" passwd = "password1111" host = "mail.privateemail.com" port = "465" ) func main() { from := "[email protected]" to := []string{ "[email protected]", } msg := []byte("from: [email protected]\r\n" + "to: [email protected]" + "subject: golang testing mail\r\n" + "email body: welcome to go!\r\n") auth := smtp.plainauth("", username, passwd, host) url := fmt.sprintf(host + ":" + port) fmt.printf("url=[%s]\n", url) err := smtp.sendmail(url, auth, from, to, msg) if err != nil { log.fatal(err) } fmt.println("mail sent successfully!") }
您能否告訴我為什麼會出現以下錯誤?
read tcp 192.168.0.2:61740->198.54.122.135:465: wsarecv: an existing connection was forcibly closed by the remote host. exit status 1
我嘗試使用curl,我看到它連接到郵件伺服器,但連接已關閉。
c:\GoProjects\goemail λ curl -v --url "smtp://mail.privateemail.com:465" --user "[email protected]:password1111" --mail-from "[email protected]" --mail-rcpt "[email protected]" --upload-file sample.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 198.54.122.135:465... * Connected to mail.privateemail.com (198.54.122.135) port 465 (#0) 0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0* Recv failure: Connection was reset 0 0 0 0 0 0 0 0 --:--:-- 0:00:10 --:--:-- 0 * Closing connection 0 curl: (56) Recv failure: Connection was reset
我正在等待發送一封電子郵件。
非常感謝您的回覆。我從 https://www.php.cn/link/7104a226fe65be03fecf10f5bceff8a6 切換到實現 並且工作正常。我仍然不明白我做錯了什麼。我對 TLS 的看法是錯誤的 - 它被使用並且 go 方法也考慮到了它。
以上是發送電子郵件時發生錯誤 wsarecv:現有連線被遠端主機強行關閉的詳細內容。更多資訊請關注PHP中文網其他相關文章!