V
V
Vadim Rublev2021-10-01 22:55:50
go
Vadim Rublev, 2021-10-01 22:55:50

Why does it give an error when sending a letter?

Why does it give an error " wrong host name "? Same for https://smtp.mail.ru:25 and smtp.mail.ru:25 . The host is copied from a working email.

from := os.Getenv("[email protected]")
password := os.Getenv("myPass")
toList := []string{"[email protected]"}
host := "https://smtp.mail.ru:25"
bodyMsg := []byte("Hello geeks!!!")
auth := smtp.PlainAuth("", from, password, host)
err := smtp.SendMail(host, auth, from, toList, bodyMsg)

Sending from a local TLS server.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Mamonov, 2021-10-04
@Vadim Rublev

I suspect that the error is in this line, you specify the port (: 25), you need to remove it.

// у вас host = "https://smtp.mail.ru:25", а должен быть "smtp.mail.ru"
auth := smtp.PlainAuth("", from, password, host)

As far as I can see, you are parsing an example from the official package https://pkg.go.dev/net/smtp
Added a couple of comments there
import (
  "log"
  "net/smtp"
)

func main() {
  // Set up authentication information.
        // тут порт не указан, скорее всего ругается именно в этой строке
  auth := smtp.PlainAuth("", "[email protected]", "password", "mail.example.com")

  // Connect to the server, authenticate, set the sender and recipient,
  // and send the email all in one step.
  to := []string{"[email protected]"}
  msg := []byte("To: [email protected]\r\n" +
    "Subject: discount Gophers!\r\n" +
    "\r\n" +
    "This is the email body.\r\n")
        // тут порт указан, т.е. host:port, но не указывается протокол типа https, тут протокол SMTP
  err := smtp.SendMail("mail.example.com:25", auth, "[email protected]", to, msg)
  if err != nil {
    log.Fatal(err)
  }
}

P
Papa, 2021-10-01
Stifflera @PapaStifflera

Because the host is smtp.mail.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question