我想使用Amazon SMTP发送电子邮件。
我正在使用示例
https://gist.github.com/jim3ma/b5c9edeac77ac92157f8f8affa290f45
但不起作用!
我收到此消息错误:
tls:第一条记录看起来不像TLS握手 恐慌:tls:第一条记录看起来不像TLS握手
答案 0 :(得分:0)
尝试使用https://golang.org/pkg/net/smtp/#example_SendMail中的代码
package main
import (
"log"
"net/smtp"
)
func main() {
// Set up authentication information.
auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com")
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
to := []string{"recipient@example.net"}
msg := []byte("To: recipient@example.net\r\n" +
"Subject: discount Gophers!\r\n" +
"\r\n" +
"This is the email body.\r\n")
err := smtp.SendMail("mail.example.com:25", auth, "sender@example.org", to, msg)
if err != nil {
log.Fatal(err)
}
}