Golang smtp.SendMail blocking

I tried using smtp.SendMail()go in the program. However, it locks and does not return until the time runs out. This prevents me from knowing what is wrong.

My code is:

to := []string{"recepient@example.com"}
err := smtp.SendMail("smtp.web.de:25", smtp.CRAMMD5Auth("example@web.de", "password"), "example@web.de", to, []byte("hi"))
if err != nil {
    fmt.Println(err)
}else{
    fmt.Println("Success")
}

After a long time, I get the following error:

dial tcp 213.165.67.124:25: connection timed out

Any ideas what could be the real issue?

+4
source share
2 answers

If you see a timeout, you can try using net.Dial directly to test connectivity:

conn, err := net.Dial("tcp", "smtp.web.de:25")
if err != nil {
    fmt.Println(err)
}

If this is not a connection, then there is something local that blocks the socket. Ask locals about setting up a firewall or about any network proxy devices that intercept outgoing traffic.

0
source

, , : 25 , .

-2

All Articles