实现Auth接口
type auth struct { host string username string password string } func (a *auth) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error) { if !server.TLS { advertised := false for _, mechanism := range server.Auth { if mechanism == "LOGIN" { advertised = true break } } if !advertised { return "", nil, errors.New("gomail: unencrypted connection") } } //if server.Name != a.host { // return "", nil, errors.New("gomail: wrong host name") //} return "LOGIN", nil, nil } func (a *auth) Next(fromServer []byte, more bool) (toServer []byte, err error) { if !more { return nil, nil } switch { case bytes.Equal(fromServer, []byte("Username:")): return []byte(a.username), nil case bytes.Equal(fromServer, []byte("Password:")): return []byte(a.password), nil default: return nil, fmt.Errorf("gomail: unexpected server challenge: %s", fromServer) } }
使用auth
dialer.Auth = &auth{ username: username, password: password, host: host, }
标签:return,nil,host,auth,connection,报错,unencrypted,gomail,byte From: https://www.cnblogs.com/liudongcai/p/17753880.html