我尝试使用go和sendgrid发送ssl电子邮件,而我遇到了此错误的一个问题:
2019/06/18 19:40:25 tls: first record does not look like a TLS handshake
panic: tls: first record does not look like a TLS handshake
/Users/admin/go/src/github.com/username/emailsender/sendme/sshMailer/smtp-sender.go:15 +0xace
main.sendEmail(0x2, 0x7fffd822f795, 0x11, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00022c3c0, 0xc00023e240)
emailsender/easysend.go:87 +0x7ba
main.worker(0xc00023e240, 0xc00022c3c0, 0xc000220220)
emailsender/easysend.go:110 +0xfa
created by main.main
emailsender/easysend.go:209 +0x418
我当前的代码是这样的:
01: // SmtpSendOne - send email using smtp & proxy
02: func SmtpSendOne(server SmtpServer, data *MailData) error {
03:
04: var remote net.Conn
05: var err error
06:
07:
08:
09: // TLS config
10: tlsconfig := &tls.Config{
11: InsecureSkipVerify: true,
12: ServerName: server.Host,
13: }
14:
15: remote, err := tls.Dial("tcp", server.GetHostFull(), tlsconfig)
16: if err != nil {
17: log.Panic(err)
18: }
19: defer remote.Close()
20:
21: if err != nil {
22: return fmt.Errorf("Failed to connect to SMTP server: %s", err)
23: }
24:
我如何解决此错误? tls: first record does not look like a TLS handshake
吗?