Как отправить электронную почту, используя Amazon SMTP с портом 587 - PullRequest
0 голосов
/ 29 сентября 2018

Я хочу отправить электронное письмо с помощью Amazon SMTP.

Я использую пример

https://gist.github.com/jim3ma/b5c9edeac77ac92157f8f8affa290f45

, но не работает!

Iполучено это сообщение об ошибке:

tls: первая запись не выглядит как рукопожатие TLS паника: tls: первая запись не выглядит как рукопожатие TLS

1 Ответ

0 голосов
/ 30 сентября 2018

Попробуйте использовать код из 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)
    }
}
...