发送电子邮件时出现错误 wsarecv:现有连接被远程主机强行关闭
问题内容
我有下面的 go 程序,它会发送电子邮件。凭证是正确的。我什至用curl测试了它们,我发现连接是成功的。请注意,tls 不是必需的。
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]rn" + "to: [email protected]" + "subject: golang testing mailrn" + "email body: welcome to go!rn") 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!") }登录后复制