I try to connect on smtp server and read welcome message. This is my code:
package main
import (
"fmt"
"net"
"time"
"net/smtp"
"bufio"
)
func main() {
// attempt a connection
conn, _ := net.DialTimeout("tcp", "88.198.24.108:25", 15 * time.Second)
buf := bufio.NewReader(conn)
bytes, _ := buf.ReadBytes('\n')
fmt.Printf("%s", bytes)
client, err := smtp.NewClient(conn, "88.198.24.108")
if err != nil {
fmt.Println("1>>", err)
return
}
client.Quit()
conn.Close()
}
Problem is after read welcome message stop running and wait to go in timeout, I want to read/print welcome message and continue.
220 example.me ESMTP Haraka/2.8.18 ready
1>> 421 timeout
An inspection of the standard library source indicates that
smtp.NewClient()
reads the SMTP banner from the remote host and throws it away.You want to read this banner and decide whether to send mail based on its contents.
Since you have already read the banner yourself, and presumably will make a decision on that, instead of calling
smtp.NewClient()
you should then implement the rest ofNewClient()
in your own code, possibly something like this: