I
I
impressive172020-06-16 20:51:45
go
impressive17, 2020-06-16 20:51:45

How to send an email using Go (JP)?

I need to send an email to @gmail. How can I do this on GO? Tried like this:

auth := smtp.PlainAuth("", "[email protected]", "....", "smtp.gmail.com")

  to := []string{"[email protected]"}
  msg := []byte("To: [email protected]\r\n" +
    "Subject: YES!\r\n" +
    "\r\n" +
    "This is the email body.\r\n")
  err := smtp.SendMail("smtp.gmail.com:587", auth, "[email protected]", to, msg)
  if err != nil {
    log.Fatal(err)
  }

But the error "unencrypted connection" crashes
And I did not find how to treat it

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question