smtp.Dial(“ASPMX.L.GOOGLE.COM:25”) 连接错误;但是 putty 连接可以正常工作。

huangapple go评论73阅读模式
英文:

smtp.Dial("ASPMX.L.GOOGLE.COM:25") connection error; but putty connections work

问题

当使用Go语言和smtp.Dial或者net.Dial时,我遇到了以下错误:

dial tcp 64.233.169.27:25: ConnectEx tcp: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

这是由以下代码引起的:

mxClient, err := smtp.Dial("ASPMX.L.GOOGLE.COM:25")
if err != nil {
    fmt.Println(err)
}

我不明白的是,我可以使用putty在25端口上连接并发送命令(如HELO),而不使用TLS。如果这是包无法建立连接的限制,是否有一种推荐的方法在Go中建立类似putty的原始套接字连接?

英文:

When using Go and smtp.Dial,
or even net.Dial,
I get the error:

> dial tcp 64.233.169.27:25: ConnectEx tcp: A connection attempt failed
> because the connected party did not properly respond after a period of
> time, or established connection failed because connected host has
> failed to respond.

From this code:

mxClient, err := smtp.Dial("ASPMX.L.GOOGLE.COM:25")
if err != nil {
	fmt.Println(err)
}

What I don't understand is that I can connect and send commands (HELO, etc) using putty on port 25 without TLS.
If it's a limitation of the package not able to make the connection,
is there a recommended way to make a raw socket connection like putty in Go?

答案1

得分: 1

我在我的机器上没有看到任何错误。

package main

import (
	"fmt"
	"net/smtp"
)

func main() {
	mxClient, err := smtp.Dial("ASPMX.L.GOOGLE.COM:25")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("%#v", mxClient)
}

输出结果为:

&smtp.Client{Text:(*textproto.Conn)(0xc208074000), conn:(*net.TCPConn)(0xc20802c018), tls:false, serverName:"ASPMX.L.GOOGLE.COM", ext:map[string]string(nil), auth:[]string(nil), localName:"localhost", didHello:false, helloError:error(nil)}
英文:

I don't see any error on my machine.

package main

import (
        "fmt"
        "net/smtp"
)

func main() {
        mxClient, err := smtp.Dial("ASPMX.L.GOOGLE.COM:25")
        if err != nil {
                fmt.Println(err)
        }
        fmt.Printf("%#v", mxClient)
}

gives

&smtp.Client{Text:(*textproto.Conn)(0xc208074000), conn:(*net.TCPConn)(0xc20802c018), tls:false, serverName:"ASPMX.L.GOOGLE.COM", ext:map[string]string(nil), auth:[]string(nil), localName:"localhost", didHello:false, helloError:error(nil)}

答案2

得分: 0

您的ISP可能会阻止25号端口。我必须使用587号端口连接到谷歌的SMTP服务器。

英文:

Your ISP might be blocking port 25. I have to use port 587 to googles smtp server to connect.

huangapple
  • 本文由 发表于 2015年5月20日 15:20:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/30342881.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定