
Kandungan soalan
Saya mempunyai program go berikut yang menghantar e-mel. Bukti kelayakan adalah betul. Saya juga mengujinya dengan curl dan saya mendapati sambungan itu berjaya. Ambil perhatian bahawa tls tidak diperlukan.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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!" )
}
|
Salin selepas log masuk
Bolehkah anda beritahu saya mengapa ralat berikut berlaku?
1 2 | 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
|
Salin selepas log masuk
Saya cuba menggunakan curl dan saya nampak ia disambungkan ke pelayan mel tetapi sambungan telah ditutup.
1 2 3 4 5 6 7 8 9 10 | 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
|
Salin selepas log masuk
Saya sedang menunggu e-mel dihantar.
Penyelesaian
Terima kasih banyak atas balasan anda. Saya bertukar kepada pelaksanaan daripada https://www.php.cn/link/7104a226fe65be03fecf10f5bceff8a6
dan berfungsi dengan baik. Saya masih tidak faham apa salah saya. Saya silap tentang TLS - ia digunakan dan kaedah go mengambil kiranya.
Atas ialah kandungan terperinci Ralat semasa menghantar e-mel wsarecv: Sambungan sedia ada telah ditutup secara paksa oleh hos jauh. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!